Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(event cache store): shortcut when there's no duplicate events to check at all #4665

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading