* perf: add composite index on session_id and timestamp to chat_messages Fixes a high-severity performance issue (PERF-08) described in issue #276. A full table scan and in-memory sort were previously performed during each session-switch or cache-load due to a missing index. By adding a composite index on `(session_id, timestamp)` in the `ChatMessageEntity` and bumping the database version from 1 to 2 with a migration, the query for loading messages now avoids the full table scan, making chat loading latency independent of total message count. Changes made: - Added `indices` to `@Entity` in `ChatMessageEntity.kt` for `session_id` and `timestamp`. - Bumped `version` to 2 in `HermesDatabase.kt`. - Added explicit migration `MIGRATION_1_2` to create the index if it doesn't exist and added it to `.addMigrations()`. Fixes #276 * style: fix ktlint formatting errors in HermesDatabase.kt Fixed `standard:argument-list-wrapping` and `standard:max-line-length` ktlint errors in `app/src/main/java/com/m57/hermescontrol/data/local/HermesDatabase.kt`. This ensures that the repository meets standard code style guidelines and fixes the GitHub CI build check failures.
83 lines
2.5 KiB
JSON
83 lines
2.5 KiB
JSON
{
|
|
"formatVersion": 1,
|
|
"database": {
|
|
"version": 2,
|
|
"identityHash": "b0a33c5fd32118982236698f395f519b",
|
|
"entities": [
|
|
{
|
|
"tableName": "chat_messages",
|
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `session_id` TEXT NOT NULL, `role` TEXT NOT NULL, `content` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, `tool_name` TEXT, `tool_status` TEXT, `is_streaming` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
|
"fields": [
|
|
{
|
|
"fieldPath": "id",
|
|
"columnName": "id",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "sessionId",
|
|
"columnName": "session_id",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "role",
|
|
"columnName": "role",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "content",
|
|
"columnName": "content",
|
|
"affinity": "TEXT",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "timestamp",
|
|
"columnName": "timestamp",
|
|
"affinity": "INTEGER",
|
|
"notNull": true
|
|
},
|
|
{
|
|
"fieldPath": "toolName",
|
|
"columnName": "tool_name",
|
|
"affinity": "TEXT"
|
|
},
|
|
{
|
|
"fieldPath": "toolStatus",
|
|
"columnName": "tool_status",
|
|
"affinity": "TEXT"
|
|
},
|
|
{
|
|
"fieldPath": "isStreaming",
|
|
"columnName": "is_streaming",
|
|
"affinity": "INTEGER",
|
|
"notNull": true
|
|
}
|
|
],
|
|
"primaryKey": {
|
|
"autoGenerate": false,
|
|
"columnNames": [
|
|
"id"
|
|
]
|
|
},
|
|
"indices": [
|
|
{
|
|
"name": "index_chat_messages_session_id_timestamp",
|
|
"unique": false,
|
|
"columnNames": [
|
|
"session_id",
|
|
"timestamp"
|
|
],
|
|
"orders": [],
|
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_chat_messages_session_id_timestamp` ON `${TABLE_NAME}` (`session_id`, `timestamp`)"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"setupQueries": [
|
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'b0a33c5fd32118982236698f395f519b')"
|
|
]
|
|
}
|
|
} |