Skip to content

Commit bedcbfd

Browse files
committed
fix(event cache): don't return an error when a linked chunk is empty
The metadata loading shouldn't cause an error to be displayed, when the linked chunk is empty; this can happen for new rooms we've never visited. Spotted while investigating some failures in a rageshake.
1 parent 743dec9 commit bedcbfd

File tree

1 file changed

+8
-3
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+8
-3
lines changed

crates/matrix-sdk/src/event_cache/room/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ mod private {
600600
// indicates that at some point, there's some malformed data.
601601
let full_linked_chunk_metadata =
602602
match Self::load_linked_chunk_metadata(&*store_lock, linked_chunk_id).await {
603-
Ok(metas) => Some(metas),
603+
Ok(metas) => metas,
604604
Err(err) => {
605605
error!(
606606
"error when loading a linked chunk's metadata from the store: {err}"
@@ -650,12 +650,17 @@ mod private {
650650
async fn load_linked_chunk_metadata(
651651
store: &DynEventCacheStore,
652652
linked_chunk_id: LinkedChunkId<'_>,
653-
) -> Result<Vec<ChunkMetadata>, EventCacheError> {
653+
) -> Result<Option<Vec<ChunkMetadata>>, EventCacheError> {
654654
let mut all_chunks = store
655655
.load_all_chunks_metadata(linked_chunk_id)
656656
.await
657657
.map_err(EventCacheError::from)?;
658658

659+
if all_chunks.is_empty() {
660+
// There are no chunks, so there's nothing to do.
661+
return Ok(None);
662+
}
663+
659664
// Transform the vector into a hashmap, for quick lookup of the predecessors.
660665
let chunk_map: HashMap<_, _> =
661666
all_chunks.iter().map(|meta| (meta.identifier, meta)).collect();
@@ -759,7 +764,7 @@ mod private {
759764
}
760765
}
761766

762-
Ok(all_chunks)
767+
Ok(Some(all_chunks))
763768
}
764769

765770
/// Given a fully-loaded linked chunk with no gaps, return the

0 commit comments

Comments
 (0)