Skip to content

Commit

Permalink
refactor(event cache): eliminate intermediate function `append_events…
Browse files Browse the repository at this point in the history
…_locked`

and replace it with an inlined call to `append_events_locked_impl`,
that's then renamed `append_events_locked`.
  • Loading branch information
bnjbvr committed Jan 9, 2025
1 parent 0915eee commit 8e0ee47
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions crates/matrix-sdk/src/event_cache/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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<SyncTimelineEvent>,
prev_batch: Option<String>,
ephemeral_events: Vec<Raw<AnySyncEphemeralRoomEvent>>,
ambiguity_changes: BTreeMap<OwnedEventId, AmbiguityChange>,
) -> 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<SyncTimelineEvent>,
Expand Down

0 comments on commit 8e0ee47

Please sign in to comment.