Skip to content

Commit

Permalink
fixup! lets deal with propagate_changes and updates drain
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Feb 7, 2025
1 parent 6c1ea4f commit b0069b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 10 additions & 1 deletion crates/matrix-sdk/src/event_cache/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@ impl RoomPagination {

// Try to load one chunk backwards. If it returns `Some(_)`, it means new events
// have been inserted. No need to reach the network!
if let Some((events, reached_start)) = state.load_one_chunk_backwards().await? {
if let Some(((events, reached_start), sync_timeline_events_diffs)) =
state.load_one_chunk_backwards().await?
{
if !sync_timeline_events_diffs.is_empty() {
let _ = self.inner.sender.send(RoomEventCacheUpdate::UpdateTimelineEvents {
diffs: sync_timeline_events_diffs,
origin: EventsOrigin::Pagination,
});
}

return Ok(Some(BackPaginationOutcome { reached_start, events }));
}
}
Expand Down
19 changes: 17 additions & 2 deletions crates/matrix-sdk/src/event_cache/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,16 @@ mod private {
/// Return `Ok(Some(events, reached_start))` if events have been
/// inserted, `Ok(None)` if a gap has been inserted or if the
/// store is disabled.
#[must_use = "Updates as `VectorDiff` must probably be propagated via `RoomEventCacheUpdate`"]
pub async fn load_one_chunk_backwards(
&mut self,
) -> Result<Option<(Vec<TimelineEvent>, bool)>, EventCacheError> {
) -> Result<
Option<((Vec<TimelineEvent>, bool), Vec<VectorDiff<TimelineEvent>>)>,
EventCacheError,
> {
// ⚠️ Propagate all pending updates before we do anything.
self.propagate_changes().await?;

let Some(store) = self.store.get() else {
// No store: no events to insert.
return Ok(None);
Expand Down Expand Up @@ -788,7 +795,15 @@ mod private {

self.events.insert_new_chunk_as_first(new_first_chunk);

Ok(result)
// ⚠️ Let's not propagate the updates to the store! We already have these data
// in the store! Let's drain them.
let _ = self.events.updates().take();

// However, we want to get updates as `VectorDiff`s.
let updates_as_vector_diffs = self.events.updates_as_vector_diffs();

Ok(result
.map(|(events, reached_start)| ((events, reached_start), updates_as_vector_diffs)))
}
}
}
Expand Down

0 comments on commit b0069b0

Please sign in to comment.