@@ -310,12 +310,26 @@ impl_event_cache_store! {
310
310
if transaction. get_chunks_count_in_room( room_id) . await ? == 0 {
311
311
return Ok ( ( None , ChunkIdentifierGenerator :: new_from_scratch( ) ) ) ;
312
312
}
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.
313
316
match transaction. get_chunk_by_next_chunk_id( room_id, & None ) . await {
314
317
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.
315
321
Err ( IndexeddbEventCacheStoreError :: ChunksContainDisjointLists )
316
322
}
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
+ } ,
319
333
Ok ( Some ( last_chunk) ) => {
320
334
let last_chunk_identifier = ChunkIdentifier :: new( last_chunk. identifier) ;
321
335
let last_raw_chunk = transaction
0 commit comments