Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pagination: don't hold onto the waited_for_initial_prev_token lock for long #3501

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/matrix-sdk/src/event_cache/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,18 @@ impl RoomPagination {
Ok(Some(BackPaginationOutcome { events, reached_start }))
}

/// Test-only function to get the latest pagination token, as stored in the
/// room events linked list.
/// Get the latest pagination token, as stored in the room events linked
/// list.
#[doc(hidden)]
pub async fn get_or_wait_for_token(&self) -> Option<String> {
const DEFAULT_INITIAL_WAIT_DURATION: Duration = Duration::from_secs(3);

let mut waited = self.inner.pagination.waited_for_initial_prev_token.lock().await;
if *waited {
let waited = *self.inner.pagination.waited_for_initial_prev_token.lock().await;
if waited {
self.oldest_token(None).await
} else {
let token = self.oldest_token(Some(DEFAULT_INITIAL_WAIT_DURATION)).await;
*waited = true;
*self.inner.pagination.waited_for_initial_prev_token.lock().await = true;
token
}
}
Expand Down
Loading