Skip to content

Commit 25ed7ee

Browse files
mgoldenbergHywan
authored andcommitted
doc(indexeddb): add explanation of error types in EventCacheStore::load_last_chunk
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
1 parent a399840 commit 25ed7ee

File tree

1 file changed

+16
-2
lines changed
  • crates/matrix-sdk-indexeddb/src/event_cache_store

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,26 @@ impl_event_cache_store! {
310310
if transaction.get_chunks_count_in_room(room_id).await? == 0 {
311311
return Ok((None, ChunkIdentifierGenerator::new_from_scratch()));
312312
}
313+
// Now that we know we have some chunks in the room, we query IndexedDB
314+
// for the last chunk in the room by getting the chunk which does not
315+
// have a next chunk.
313316
match transaction.get_chunk_by_next_chunk_id(room_id, &None).await {
314317
Err(IndexeddbEventCacheStoreTransactionError::ItemIsNotUnique) => {
318+
// If there are multiple chunks that do not have a next chunk, that
319+
// means we have more than one last chunk, which means that we have
320+
// more than one list in the room.
315321
Err(IndexeddbEventCacheStoreError::ChunksContainDisjointLists)
316322
}
317-
Err(e) => Err(e.into()),
318-
Ok(None) => Err(IndexeddbEventCacheStoreError::ChunksContainCycle),
323+
Err(e) => {
324+
// There was some error querying IndexedDB, but it is not necessarily
325+
// a violation of our data constraints.
326+
Err(e.into())
327+
},
328+
Ok(None) => {
329+
// If there is no chunk without a next chunk, that means every chunk
330+
// points to another chunk, which means that we have a cycle in our list.
331+
Err(IndexeddbEventCacheStoreError::ChunksContainCycle)
332+
},
319333
Ok(Some(last_chunk)) => {
320334
let last_chunk_identifier = ChunkIdentifier::new(last_chunk.identifier);
321335
let last_raw_chunk = transaction

0 commit comments

Comments
 (0)