Skip to content

Commit 7942759

Browse files
committed
chore(spaces): acquire and retain an async lock on the pagination token for the duration of the request to futher prevent inconsistencies
1 parent 8f4d3d1 commit 7942759

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

crates/matrix-sdk-ui/src/spaces/room_list.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use itertools::Itertools;
2222
use matrix_sdk::{Client, Error, executor::AbortOnDrop, locks::Mutex, paginators::PaginationToken};
2323
use matrix_sdk_common::executor::spawn;
2424
use ruma::{OwnedRoomId, api::client::space::get_hierarchy, uint};
25+
use tokio::sync::Mutex as AsyncMutex;
2526
use tracing::error;
2627

2728
use crate::spaces::SpaceRoom;
@@ -98,7 +99,7 @@ pub struct SpaceRoomList {
9899

99100
parent_space_id: OwnedRoomId,
100101

101-
token: Mutex<PaginationToken>,
102+
token: AsyncMutex<PaginationToken>,
102103

103104
pagination_state: SharedObservable<SpaceRoomListPaginationState>,
104105

@@ -155,7 +156,7 @@ impl SpaceRoomList {
155156
Self {
156157
client,
157158
parent_space_id,
158-
token: Mutex::new(None.into()),
159+
token: AsyncMutex::new(None.into()),
159160
pagination_state: SharedObservable::new(SpaceRoomListPaginationState::Idle {
160161
end_reached: false,
161162
}),
@@ -206,14 +207,15 @@ impl SpaceRoomList {
206207
let mut request = get_hierarchy::v1::Request::new(self.parent_space_id.clone());
207208
request.max_depth = Some(uint!(1)); // We only want the immediate children of the space
208209

209-
if let PaginationToken::HasMore(ref token) = *self.token.lock() {
210+
let mut pagination_token = self.token.lock().await;
211+
212+
if let PaginationToken::HasMore(ref token) = *pagination_token {
210213
request.from = Some(token.clone());
211214
}
212215

213216
match self.client.send(request).await {
214217
Ok(result) => {
215-
let mut token = self.token.lock();
216-
*token = match &result.next_batch {
218+
*pagination_token = match &result.next_batch {
217219
Some(val) => PaginationToken::HasMore(val.clone()),
218220
None => PaginationToken::HitEnd,
219221
};

0 commit comments

Comments
 (0)