Skip to content

Commit

Permalink
fix(event cache store): shortcut when there's no duplicate events to …
Browse files Browse the repository at this point in the history
…check at all

Otherwise this causes a panic when repeating the events variable, when
generating the SQL query below.
  • Loading branch information
bnjbvr committed Feb 13, 2025
1 parent 861078a commit 1068d88
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/matrix-sdk-sqlite/src/event_cache_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ impl EventCacheStore for SqliteEventCacheStore {
room_id: &RoomId,
events: Vec<OwnedEventId>,
) -> Result<Vec<OwnedEventId>, 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);
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 1068d88

Please sign in to comment.