Skip to content

Commit

Permalink
fix(base): clear a room's send queue and dependent event queue after …
Browse files Browse the repository at this point in the history
…removing it from the state store
  • Loading branch information
bnjbvr committed Nov 19, 2024
1 parent 0b16d48 commit 56863b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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

0 comments on commit 56863b4

Please sign in to comment.