refactor(store): extend message store interface with store manipulation methods

This commit is contained in:
Lorenzo Delgado 2022-09-15 21:12:13 +02:00 committed by GitHub
parent 70fdd85066
commit 706c355b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -46,4 +46,16 @@ method getMessagesByHistoryQuery*(
ascendingOrder = true
): MessageStoreResult[MessageStorePage] {.base.} = discard
# Store manipulation
method getMessagesCount*(ms: MessageStore): MessageStoreResult[int64] {.base.} = discard
method getOldestMessageTimestamp*(ms: MessageStore): MessageStoreResult[Timestamp] {.base.} = discard
method getNewestMessageTimestamp*(ms: MessageStore): MessageStoreResult[Timestamp] {.base.} = discard
method deleteMessagesOlderThanTimestamp*(ms: MessageStore, ts: Timestamp): MessageStoreResult[void] {.base.} = discard
method deleteOldestMessagesNotWithinLimit*(ms: MessageStore, limit: int): MessageStoreResult[void] {.base.} = discard

View File

@ -158,3 +158,16 @@ method getMessagesByHistoryQuery*(
method getMessagesCount*(s: SqliteStore): MessageStoreResult[int64] =
s.db.getMessageCount()
method getOldestMessageTimestamp*(s: SqliteStore): MessageStoreResult[Timestamp] =
s.db.selectOldestReceiverTimestamp()
method getNewestMessageTimestamp*(s: SqliteStore): MessageStoreResult[Timestamp] =
s.db.selectnewestReceiverTimestamp()
method deleteMessagesOlderThanTimestamp*(s: SqliteStore, ts: Timestamp): MessageStoreResult[void] =
s.db.deleteMessagesOlderThanTimestamp(ts)
method deleteOldestMessagesNotWithinLimit*(s: SqliteStore, limit: int): MessageStoreResult[void] =
s.db.deleteOldestMessagesNotWithinLimit(limit)

View File

@ -430,3 +430,17 @@ method getMessagesByHistoryQuery*(
method getMessagesCount*(s: StoreQueueRef): MessageStoreResult[int64] =
ok(int64(s.len()))
method getOldestMessageTimestamp*(s: StoreQueueRef): MessageStoreResult[Timestamp] =
s.first().map(proc(msg: IndexedWakuMessage): Timestamp = msg.index.receiverTime)
method getNewestMessageTimestamp*(s: StoreQueueRef): MessageStoreResult[Timestamp] =
s.last().map(proc(msg: IndexedWakuMessage): Timestamp = msg.index.receiverTime)
method deleteMessagesOlderThanTimestamp*(s: StoreQueueRef, ts: Timestamp): MessageStoreResult[void] =
# TODO: Implement this message_store method
err("interface method not implemented")
method deleteOldestMessagesNotWithinLimit*(s: StoreQueueRef, limit: int): MessageStoreResult[void] =
# TODO: Implement this message_store method
err("interface method not implemented")