Skip to content

Commit

Permalink
refactor(event cache): apply review comments of #4708
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Feb 25, 2025
1 parent 475ad79 commit 0819ab1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
.await
.unwrap();

// Now let's find out the event.
// Now let's find the event.
let (position, event) = self
.find_event(room_id, event_comte.event_id().unwrap().as_ref())
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl EventCacheStore for MemoryStore {

let mut duplicated_events = Vec::new();

for (event, position) in inner.events.unordered_items(room_id) {
for (event, position) in inner.events.unordered_room_items(room_id) {
// If `events` is empty, we can short-circuit.
if events.is_empty() {
break;
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-common/src/linked_chunk/relational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
}
}

/// Return an iterator that yields items of a particular room with no
/// Return an iterator that yields items of a particular room, in no
/// particular order.
pub fn unordered_items<'a>(
pub fn unordered_room_items<'a>(
&'a self,
room_id: &'a RoomId,
) -> impl Iterator<Item = (&'a Item, Position)> {
Expand All @@ -311,7 +311,7 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
})
}

/// Return an iterator over all items.
/// Return an iterator over all items of all rooms, in no particular order.
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 {
Expand Down Expand Up @@ -1142,7 +1142,7 @@ mod tests {
],
);

let mut events = relational_linked_chunk.unordered_items(room_id);
let mut events = relational_linked_chunk.unordered_room_items(room_id);

assert_eq!(events.next().unwrap(), (&'a', Position::new(CId::new(0), 0)));
assert_eq!(events.next().unwrap(), (&'b', Position::new(CId::new(0), 1)));
Expand Down
5 changes: 2 additions & 3 deletions crates/matrix-sdk/src/event_cache/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ impl RoomEventCache {
return None;
};

// Search in `AllEventsCache` for known events that are not stored.
if let Some(event) = maybe_position_and_event.map(|(_position, event)| event) {
Some(event)
}
// Search in `AllEventsCache` for known events that are not stored.
else if let Some((room_id, event)) =
} else if let Some((room_id, event)) =
self.inner.all_events.read().await.events.get(event_id).cloned()
{
(room_id == self.inner.room_id).then_some(event)
Expand Down

0 comments on commit 0819ab1

Please sign in to comment.