Skip to content

Commit a152f9c

Browse files
committed
refactor(event cache): remove one caller of with_events_mut
The actual code useful in `with_events_mut` and used in that function was to propagate the changes to the store and propagating diffs to observers. It often striked me as hacky to use this method to do that, so instead I'm proposing here to inline the useful bits. That way, `with_events_mut` is now clearly called only in two cases: after a sync, or after a successful network back-pagination.
1 parent 50be8a1 commit a152f9c

File tree

1 file changed

+14
-19
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+14
-19
lines changed

crates/matrix-sdk/src/event_cache/room/mod.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -965,26 +965,21 @@ mod private {
965965
}
966966

967967
// In-memory events.
968-
let timeline_event_diffs = if !in_memory_events.is_empty() {
969-
self.with_events_mut(|room_events| {
970-
// `remove_events_by_position` sorts the positions by itself.
971-
room_events
972-
.remove_events_by_position(
973-
in_memory_events
974-
.into_iter()
975-
.map(|(_event_id, position)| position)
976-
.collect(),
977-
)
978-
.expect("failed to remove an event");
979-
980-
vec![]
981-
})
982-
.await?
983-
} else {
984-
Vec::new()
985-
};
968+
if in_memory_events.is_empty() {
969+
// Nothing else to do, return early.
970+
return Ok(Vec::new());
971+
}
972+
973+
// `remove_events_by_position` is responsible of sorting positions.
974+
self.events
975+
.remove_events_by_position(
976+
in_memory_events.into_iter().map(|(_event_id, position)| position).collect(),
977+
)
978+
.expect("failed to remove an event");
979+
980+
self.propagate_changes().await?;
986981

987-
Ok(timeline_event_diffs)
982+
Ok(self.events.updates_as_vector_diffs())
988983
}
989984

990985
/// Propagate changes to the underlying storage.

0 commit comments

Comments
 (0)