Skip to content

fix(sdk): RoomEventCache::event looks inside the store #4708

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

Merged
merged 2 commits into from
Feb 25, 2025

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Feb 24, 2025

This patch fixes a bug in RoomEventCache::event since #4632 has landed. RoomEvents now likely contains a partial view of the events, i.e. they are not all loaded from the store to memory.

A new EventCacheStore::find_event is added to look for an event in the store. RoomEventCache::event uses it to use the store, with a fallback to AllEventsCache because we can't get rid of it right now (see #3886).

@Hywan Hywan requested a review from jmartinesp February 24, 2025 13:35
Copy link

codecov bot commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 96.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 85.97%. Comparing base (e5f6d02) to head (5cc427d).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/event_cache/room/mod.rs 88.23% 2 Missing ⚠️
crates/matrix-sdk-sqlite/src/event_cache_store.rs 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4708      +/-   ##
==========================================
+ Coverage   85.96%   85.97%   +0.01%     
==========================================
  Files         290      290              
  Lines       33995    34065      +70     
==========================================
+ Hits        29224    29288      +64     
- Misses       4771     4777       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hywan Hywan force-pushed the feat-sdk-event-cache-event-in-store branch from 9c1d4cd to 985807a Compare February 24, 2025 15:04
@Hywan Hywan marked this pull request as ready for review February 24, 2025 15:05
@Hywan Hywan requested a review from a team as a code owner February 24, 2025 15:05
@Hywan Hywan force-pushed the feat-sdk-event-cache-event-in-store branch from 985807a to ca62b1f Compare February 24, 2025 15:07
@Hywan Hywan requested review from bnjbvr and removed request for a team and jmartinesp February 24, 2025 16:23
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@Hywan Hywan force-pushed the feat-sdk-event-cache-event-in-store branch from ca62b1f to 78c22d7 Compare February 25, 2025 07:31
This patch adds the method `find_event` on the `EventCacheStore` trait.
It helps to find a single event from the store.
This patch fixes `RoomEventCache::event` to look inside `RoomEvents` but
also inside the `EventCacheStore` to look for an event. It ultimately
fallbacks to `AllEventsCache` because we can't get rid of it for the
moment.
@Hywan Hywan force-pushed the feat-sdk-event-cache-event-in-store branch from 0b3b134 to 5cc427d Compare February 25, 2025 10:38
@Hywan Hywan merged commit 475ad79 into matrix-org:main Feb 25, 2025
42 checks passed
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one more question about fusing two methods in the in-memory event cache store implementation, and we should be good to go, thanks!

.await
.unwrap();

// Now let's find out the event.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to double-check with a native speaker, but I find it weird to have find out here, I'd just say find I suppose.

Suggested change
// Now let's find out the event.
// Now let's find the event.

Comment on lines +314 to +323
/// Return an iterator over all items.
pub fn items(&self) -> impl Iterator<Item = (Position, &Item, &RoomId)> {
self.items.iter().filter_map(|item_row| {
if let Either::Item(item) = &item_row.item {
Some((item_row.position, item, item_row.room_id.as_ref()))
} else {
None
}
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this is unordered_items with an extra return value; can we fuse those two functions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i found the difference now, unordered_items is keyed by room. Maybe the names could be clearer…

if let Some(event) = maybe_position_and_event.map(|(_position, event)| event) {
Some(event)
}
// Search in `AllEventsCache` for known events that are not stored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put the comment either above the if / else if chain, or inside the arm that relates to it? I find it super ugly and confusing to have comments break else if chains, because it breaks the flow of reading :|

@bnjbvr
Copy link
Member

bnjbvr commented Feb 25, 2025

lol i forgot i approved yesterday

@Hywan
Copy link
Member Author

Hywan commented Feb 25, 2025

Oh damn, sorry!!

@bnjbvr
Copy link
Member

bnjbvr commented Feb 25, 2025

opened #4711 with my review suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants