perf(store): add index on receiverTimestamp (#947)

This commit is contained in:
Daniel Kaiser 2022-04-23 10:49:11 +02:00 committed by GitHub
parent f59876caeb
commit 5e85eecd14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -100,6 +100,12 @@ proc init*(T: type WakuMessageStore, db: SqliteDatabase, storeCapacity: int = 50
let numMessages = messageCount(db).get() let numMessages = messageCount(db).get()
debug "number of messages in sqlite database", messageNum=numMessages debug "number of messages in sqlite database", messageNum=numMessages
# add index on receiverTimestamp
let addIndexStmt = "CREATE INDEX IF NOT EXISTS i_rt ON " & TABLE_TITLE & "(receiverTimestamp);"
let resIndex = db.query(addIndexStmt, proc(s: ptr sqlite3_stmt) = discard)
if resIndex.isErr:
return err("Could not establish index on receiverTimestamp: " & resIndex.error)
let storeMaxLoad = int(float(storeCapacity) * MaxStoreOverflow) let storeMaxLoad = int(float(storeCapacity) * MaxStoreOverflow)
let deleteWindow = int(float(storeMaxLoad - storeCapacity) / 2) let deleteWindow = int(float(storeMaxLoad - storeCapacity) / 2)
let wms = WakuMessageStore(database: db, let wms = WakuMessageStore(database: db,