Skip to content

Commit 2a82859

Browse files
Prune old rows in device_lists_changes_in_room table. (#19473)
Fixes #13043 The usages of the table mostly already correctly handled if we don't have old entries, as that was needed when we first added the table. I arbitrarily set the prune time to 30 days. The only use for old entries is for sync streams that haven't synced since then, and we should very rarely see sync streams that haven't been used in 30 days. Reviewable commit-by-commit. --------- Co-authored-by: Olivier 'reivilibre' <oliverw@element.io> Co-authored-by: Olivier 'reivilibre' <olivier@librepush.net>
1 parent 647fb59 commit 2a82859

7 files changed

Lines changed: 818 additions & 77 deletions

File tree

changelog.d/19473.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce database disk space usage by pruning old rows from `device_lists_changes_in_room`.

synapse/handlers/device.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
DeviceListUpdates,
5959
JsonDict,
6060
JsonMapping,
61+
MultiWriterStreamToken,
6162
ScheduledTask,
6263
StrCollection,
6364
StreamKeyType,
@@ -1193,7 +1194,16 @@ async def handle_room_un_partial_stated(self, room_id: str) -> None:
11931194
changes = await self.store.get_device_list_changes_in_room(
11941195
room_id, device_lists_stream_id
11951196
)
1196-
local_changes = {(u, d) for u, d in changes if self.hs.is_mine_id(u)}
1197+
if changes is not None:
1198+
local_changes = {(u, d) for u, d in changes if self.hs.is_mine_id(u)}
1199+
else:
1200+
# The `device_lists_stream_id` is too old, so we need to fall back
1201+
# to looking for changes for all local users.
1202+
local_users = await self.store.get_local_users_in_room(room_id)
1203+
local_changes = await self.store.get_device_changes_for_users(
1204+
MultiWriterStreamToken(stream=device_lists_stream_id), local_users
1205+
)
1206+
11971207
if not local_changes:
11981208
return
11991209

0 commit comments

Comments
 (0)