mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-01 20:47:18 -04:00
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.
This commit is contained in:
@@ -965,26 +965,21 @@ mod private {
|
||||
}
|
||||
|
||||
// In-memory events.
|
||||
let timeline_event_diffs = if !in_memory_events.is_empty() {
|
||||
self.with_events_mut(|room_events| {
|
||||
// `remove_events_by_position` sorts the positions by itself.
|
||||
room_events
|
||||
.remove_events_by_position(
|
||||
in_memory_events
|
||||
.into_iter()
|
||||
.map(|(_event_id, position)| position)
|
||||
.collect(),
|
||||
)
|
||||
.expect("failed to remove an event");
|
||||
if in_memory_events.is_empty() {
|
||||
// Nothing else to do, return early.
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
vec![]
|
||||
})
|
||||
.await?
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
// `remove_events_by_position` is responsible of sorting positions.
|
||||
self.events
|
||||
.remove_events_by_position(
|
||||
in_memory_events.into_iter().map(|(_event_id, position)| position).collect(),
|
||||
)
|
||||
.expect("failed to remove an event");
|
||||
|
||||
Ok(timeline_event_diffs)
|
||||
self.propagate_changes().await?;
|
||||
|
||||
Ok(self.events.updates_as_vector_diffs())
|
||||
}
|
||||
|
||||
/// Propagate changes to the underlying storage.
|
||||
|
||||
Reference in New Issue
Block a user