From 8e0ee47637c2eb0a94f1e9132b640f2f007524eb Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 7 Jan 2025 17:49:42 +0100 Subject: [PATCH] refactor(event cache): eliminate intermediate function `append_events_locked` and replace it with an inlined call to `append_events_locked_impl`, that's then renamed `append_events_locked`. --- crates/matrix-sdk/src/event_cache/room/mod.rs | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/crates/matrix-sdk/src/event_cache/room/mod.rs b/crates/matrix-sdk/src/event_cache/room/mod.rs index aa89c6ccd7..e7f9505809 100644 --- a/crates/matrix-sdk/src/event_cache/room/mod.rs +++ b/crates/matrix-sdk/src/event_cache/room/mod.rs @@ -325,7 +325,9 @@ impl RoomEventCacheInner { // so we wouldn't make use of the given previous-batch token. let prev_batch = if timeline.limited { timeline.prev_batch } else { None }; - self.append_new_events( + let mut state = self.state.write().await; + self.append_events_locked( + &mut state, timeline.events, prev_batch, ephemeral_events, @@ -366,7 +368,7 @@ impl RoomEventCacheInner { let _ = self.sender.send(RoomEventCacheUpdate::Clear); // Push the new events. - self.append_events_locked_impl( + self.append_events_locked( &mut state, sync_timeline_events, prev_batch.clone(), @@ -383,28 +385,9 @@ impl RoomEventCacheInner { /// Append a set of events to the room cache and storage, notifying /// observers. - async fn append_new_events( - &self, - sync_timeline_events: Vec, - prev_batch: Option, - ephemeral_events: Vec>, - ambiguity_changes: BTreeMap, - ) -> Result<()> { - let mut state = self.state.write().await; - self.append_events_locked_impl( - &mut state, - sync_timeline_events, - prev_batch, - ephemeral_events, - ambiguity_changes, - ) - .await - } - - /// Append a set of events and associated room data. /// /// This is a private implementation. It must not be exposed publicly. - async fn append_events_locked_impl( + async fn append_events_locked( &self, state: &mut RoomEventCacheState, sync_timeline_events: Vec,