Skip to content

Commit

Permalink
fix(event cache): get the *most recent* pagination token, not the *ol…
Browse files Browse the repository at this point in the history
…dest* one
  • Loading branch information
bnjbvr committed Dec 3, 2024
1 parent cfc0aff commit 374a421
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions crates/matrix-sdk/src/event_cache/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ impl RoomPagination {
/// Otherwise, it will immediately skip.
#[doc(hidden)]
pub async fn get_or_wait_for_token(&self, wait_time: Option<Duration>) -> Option<String> {
fn get_oldest(events: &RoomEvents) -> Option<String> {
events.chunks().find_map(|chunk| match chunk.content() {
fn get_latest(events: &RoomEvents) -> Option<String> {
events.rchunks().find_map(|chunk| match chunk.content() {
ChunkContent::Gap(gap) => Some(gap.prev_token.clone()),
ChunkContent::Items(..) => None,
})
Expand All @@ -256,7 +256,7 @@ impl RoomPagination {
// Scope for the lock guard.
let state = self.inner.state.read().await;
// Fast-path: we do have a previous-batch token already.
if let Some(found) = get_oldest(state.events()) {
if let Some(found) = get_latest(state.events()) {
return Some(found);
}
// If we've already waited for an initial previous-batch token before,
Expand All @@ -275,7 +275,7 @@ impl RoomPagination {
let _ = timeout(wait_time, self.inner.pagination_batch_token_notifier.notified()).await;

let mut state = self.inner.state.write().await;
let token = get_oldest(state.events());
let token = get_latest(state.events());
state.waited_for_initial_prev_token = true;
token
}
Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk/src/event_cache/room/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use eyeball_im::VectorDiff;
pub use matrix_sdk_base::event_cache::{Event, Gap};
use matrix_sdk_base::{
event_cache::store::DEFAULT_CHUNK_CAPACITY,
linked_chunk::{AsVector, ObservableUpdates},
linked_chunk::{AsVector, IterBackward, ObservableUpdates},
};
use matrix_sdk_common::linked_chunk::{
Chunk, ChunkIdentifier, EmptyChunk, Error, Iter, LinkedChunk, Position,
Expand Down Expand Up @@ -169,11 +169,11 @@ impl RoomEvents {
self.chunks.chunk_identifier(predicate)
}

/// Iterate over the chunks, forward.
/// Iterate over the chunks, backward.
///
/// The oldest chunk comes first.
pub fn chunks(&self) -> Iter<'_, DEFAULT_CHUNK_CAPACITY, Event, Gap> {
self.chunks.chunks()
/// The most recent chunk comes first.
pub fn rchunks(&self) -> IterBackward<'_, DEFAULT_CHUNK_CAPACITY, Event, Gap> {
self.chunks.rchunks()
}

/// Iterate over the events, backward.
Expand Down

0 comments on commit 374a421

Please sign in to comment.