Skip to content

Commit 1068d88

Browse files
committed
fix(event cache store): shortcut when there's no duplicate events to check at all
Otherwise this causes a panic when repeating the events variable, when generating the SQL query below.
1 parent 861078a commit 1068d88

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/matrix-sdk-sqlite/src/event_cache_store.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ impl EventCacheStore for SqliteEventCacheStore {
627627
room_id: &RoomId,
628628
events: Vec<OwnedEventId>,
629629
) -> Result<Vec<OwnedEventId>, Self::Error> {
630+
// If there's no events for which we want to check duplicates, we can return
631+
// early. It's not only an optimization to do so: it's required, otherwise the
632+
// `repeat_vars` call below will panic.
633+
if events.is_empty() {
634+
return Ok(Vec::new());
635+
}
636+
630637
// Select all events that exist in the store, i.e. the duplicates.
631638
let room_id = room_id.to_owned();
632639
let hashed_room_id = self.encode_key(keys::LINKED_CHUNKS, &room_id);
@@ -1805,6 +1812,15 @@ mod tests {
18051812
let chunks = store.reload_linked_chunk(room_id).await.unwrap();
18061813
assert!(chunks.is_empty());
18071814
}
1815+
1816+
#[async_test]
1817+
async fn test_filter_duplicate_events_no_events() {
1818+
let store = get_event_cache_store().await.expect("creating cache store failed");
1819+
1820+
let room_id = *DEFAULT_TEST_ROOM_ID;
1821+
let duplicates = store.filter_duplicated_events(room_id, Vec::new()).await.unwrap();
1822+
assert!(duplicates.is_empty());
1823+
}
18081824
}
18091825

18101826
#[cfg(test)]

0 commit comments

Comments
 (0)