Skip to content

Commit 153618b

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): add helper fns for EventCacheStore::load_last_chunk
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
1 parent dd871ef commit 153618b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/transaction.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,18 @@ impl<'a> IndexeddbEventCacheStoreTransaction<'a> {
406406
self.get_item_by_key_components::<Chunk, IndexedChunkIdKey>(room_id, chunk_id).await
407407
}
408408

409+
/// Query IndexedDB for chunks such that the next chunk matches the given
410+
/// chunk identifier in the given room. If more than one item is found,
411+
/// an error is returned.
412+
pub async fn get_chunk_by_next_chunk_id(
413+
&self,
414+
room_id: &RoomId,
415+
next_chunk_id: &Option<ChunkIdentifier>,
416+
) -> Result<Option<Chunk>, IndexeddbEventCacheStoreTransactionError> {
417+
self.get_item_by_key_components::<Chunk, IndexedNextChunkIdKey>(room_id, next_chunk_id)
418+
.await
419+
}
420+
409421
/// Query IndexedDB for all chunks in the given room
410422
pub async fn get_chunks_in_room(
411423
&self,
@@ -414,6 +426,22 @@ impl<'a> IndexeddbEventCacheStoreTransaction<'a> {
414426
self.get_items_in_room::<Chunk, IndexedChunkIdKey>(room_id).await
415427
}
416428

429+
/// Query IndexedDB for the number of chunks in the given room.
430+
pub async fn get_chunks_count_in_room(
431+
&self,
432+
room_id: &RoomId,
433+
) -> Result<usize, IndexeddbEventCacheStoreTransactionError> {
434+
self.get_items_count_in_room::<Chunk, IndexedChunkIdKey>(room_id).await
435+
}
436+
437+
/// Query IndexedDB for the chunk with the maximum key in the given room.
438+
pub async fn get_max_chunk_by_id(
439+
&self,
440+
room_id: &RoomId,
441+
) -> Result<Option<Chunk>, IndexeddbEventCacheStoreTransactionError> {
442+
self.get_max_item_by_key::<Chunk, IndexedChunkIdKey>(room_id).await
443+
}
444+
417445
/// Query IndexedDB for given chunk in given room and additionally query
418446
/// for events or gap, depending on chunk type, in order to construct the
419447
/// full chunk.

0 commit comments

Comments
 (0)