Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

delete messages from device_inbox table when deleting device #10098

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions changelog.d/10098.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where messages in `device_inbox` table where not deleted, when deleting device(s).
15 changes: 15 additions & 0 deletions synapse/storage/databases/main/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,12 @@ async def delete_device(self, user_id: str, device_id: str) -> None:
desc="delete_device",
)

await self.db_pool.simple_delete_many(
table="device_inbox",
keyvalues={"user_id": user_id, "device_id": device_id},
desc="delete_device",
)

self.device_id_exists_cache.invalidate((user_id, device_id))

async def delete_devices(self, user_id: str, device_ids: List[str]) -> None:
Expand All @@ -1149,6 +1155,15 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None:
keyvalues={"user_id": user_id, "hidden": False},
desc="delete_devices",
)

await self.db_pool.simple_delete_many(
table="device_inbox",
column="device_id",
iterable=device_ids,
keyvalues={"user_id": user_id},
desc="delete_devices",
)

for device_id in device_ids:
self.device_id_exists_cache.invalidate((user_id, device_id))

Expand Down