diff --git a/crates/matrix-sdk-sqlite/src/event_cache_store.rs b/crates/matrix-sdk-sqlite/src/event_cache_store.rs index 83a69f2a0d4..53b32b569b7 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -627,6 +627,13 @@ impl EventCacheStore for SqliteEventCacheStore { room_id: &RoomId, events: Vec, ) -> Result, Self::Error> { + // If there's no events for which we want to check duplicates, we can return + // early. It's not only an optimization to do so: it's required, otherwise the + // `repeat_vars` call below will panic. + if events.is_empty() { + return Ok(Vec::new()); + } + // Select all events that exist in the store, i.e. the duplicates. let room_id = room_id.to_owned(); let hashed_room_id = self.encode_key(keys::LINKED_CHUNKS, &room_id); @@ -1805,6 +1812,15 @@ mod tests { let chunks = store.reload_linked_chunk(room_id).await.unwrap(); assert!(chunks.is_empty()); } + + #[async_test] + async fn test_filter_duplicate_events_no_events() { + let store = get_event_cache_store().await.expect("creating cache store failed"); + + let room_id = *DEFAULT_TEST_ROOM_ID; + let duplicates = store.filter_duplicated_events(room_id, Vec::new()).await.unwrap(); + assert!(duplicates.is_empty()); + } } #[cfg(test)]