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

fix(base): clear a room's send queue and dependent event queue after removing it from the state store #4295

Merged
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions crates/matrix-sdk-base/src/store/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,24 @@ impl StateStoreIntegrationTests for DynStateStore {

self.populate().await?;

{
// Add a send queue request in that room.
let txn = TransactionId::new();
let ev =
SerializableEventContent::new(&RoomMessageEventContent::text_plain("sup").into())
.unwrap();
self.save_send_queue_request(room_id, txn.clone(), ev.into(), 0).await?;

// Add a single dependent queue request.
self.save_dependent_queued_request(
room_id,
&txn,
ChildTransactionId::new(),
DependentQueuedRequestKind::RedactEvent,
)
.await?;
}

self.remove_room(room_id).await?;

assert_eq!(self.get_room_infos().await?.len(), 1, "room is still there");
Expand Down Expand Up @@ -1023,6 +1041,8 @@ impl StateStoreIntegrationTests for DynStateStore {
.is_empty(),
"still event recepts in the store"
);
assert!(self.load_send_queue_requests(room_id).await?.is_empty());
assert!(self.load_dependent_queued_requests(room_id).await?.is_empty());

self.remove_room(stripped_room_id).await?;

Expand Down
2 changes: 2 additions & 0 deletions crates/matrix-sdk-base/src/store/memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ impl StateStore for MemoryStore {
self.stripped_members.write().unwrap().remove(room_id);
self.room_user_receipts.write().unwrap().remove(room_id);
self.room_event_receipts.write().unwrap().remove(room_id);
self.send_queue_events.write().unwrap().remove(room_id);
self.dependent_send_queue_events.write().unwrap().remove(room_id);

Ok(())
}
Expand Down
11 changes: 11 additions & 0 deletions crates/matrix-sdk-sqlite/src/state_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ trait SqliteConnectionStateStoreExt {
fn remove_display_name(&self, room_id: &[u8], name: &[u8]) -> rusqlite::Result<()>;
fn remove_room_display_names(&self, room_id: &[u8]) -> rusqlite::Result<()>;
fn remove_room_send_queue(&self, room_id: &[u8]) -> rusqlite::Result<()>;
fn remove_room_dependent_send_queue(&self, room_id: &[u8]) -> rusqlite::Result<()>;
}

impl SqliteConnectionStateStoreExt for rusqlite::Connection {
Expand Down Expand Up @@ -720,6 +721,12 @@ impl SqliteConnectionStateStoreExt for rusqlite::Connection {
self.prepare("DELETE FROM send_queue_events WHERE room_id = ?")?.execute((room_id,))?;
Ok(())
}

fn remove_room_dependent_send_queue(&self, room_id: &[u8]) -> rusqlite::Result<()> {
self.prepare("DELETE FROM dependent_send_queue_events WHERE room_id = ?")?
.execute((room_id,))?;
Ok(())
}
}

#[async_trait]
Expand Down Expand Up @@ -1726,6 +1733,10 @@ impl StateStore for SqliteStateStore {
let send_queue_room_id = this.encode_key(keys::SEND_QUEUE, &room_id);
txn.remove_room_send_queue(&send_queue_room_id)?;

let dependent_send_queue_room_id =
this.encode_key(keys::DEPENDENTS_SEND_QUEUE, &room_id);
txn.remove_room_dependent_send_queue(&dependent_send_queue_room_id)?;

Ok(())
})
.await
Expand Down
Loading