fix(waku-store): added an index to improve messages query time

This commit is contained in:
Lorenzo Delgado 2022-09-05 15:18:47 +02:00 committed by GitHub
parent 21e9f25276
commit 3f7aa8c6e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -76,7 +76,7 @@ proc createTable*(db: SqliteDatabase): DatabaseResult[void] {.inline.} =
## Create index
template createIndexQuery(table: string): SqlQueryStr =
"CREATE INDEX IF NOT EXISTS i_rt ON " & table & " (receiverTimestamp);"
"CREATE INDEX IF NOT EXISTS i_msg ON " & table & " (contentTopic, pubsubTopic, senderTimestamp, id);"
proc createIndex*(db: SqliteDatabase): DatabaseResult[void] {.inline.} =
let query = createIndexQuery(DbTable)

View File

@ -7,7 +7,7 @@ const MESSAGE_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts/message"
const PEER_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts/peer"
const ALL_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts"
const USER_VERSION* = 4 # increase this when there is an update in the database schema
const USER_VERSION* = 5 # increase this when there is an update in the database schema
type MigrationScriptsResult*[T] = Result[T, string]
type

View File

@ -0,0 +1,3 @@
DROP INDEX IF EXISTS i_rt;
CREATE INDEX IF NOT EXISTS i_msg ON Message (contentTopic, pubsubTopic, senderTimestamp, id);