Skip to content

Commit 1de05e5

Browse files
committed
Fix missing deletion bug
Old SOGS stores a deleted message ids table with its own separate ids that track when messages are deleted. When Session clients send a request to fetch room updates, they include a parameter "give me all deletions since deletion id X". New SOGS just stores an update counter in the room itself (because this will also be used for tracking/fetching edits, so we need more than just deletion tracking), which gets incremented on every message deletion or message update. The import set this update counter to the number of deletions that it imported -- but old SOGS had a bug where it would insert deletion rows multiple times (in one case 24 times), driving up the deletion id; the sogs import just skips over the duplicates when importing. But that caused issues because, e.g. for the Crypto room, it had a message deletion id of 5207, but only had 5108 unique deletions: so the imported crypto room got its update counter set to 5108. Thus new deletions were incrementing that update counter, as they are supposed to, but your client was still saying "give me deletions since 5207" so it never fetched the first 101 deletions. When I started testing things this morning, it was working perfectly everywhere I tested it, which was extra frustrating: turns out that's because because we've now had enough deletions to bump those update counters to be higher than the imported counter. This fixes the issue by using the max deletion id as the room.updates counter if greater than the number of room updates.
1 parent 7532bae commit 1de05e5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sogs/migrate01x.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,17 @@ def migrate01x(conn):
233233
)
234234
)
235235

236-
cur.execute("UPDATE rooms SET updates = ? WHERE id = ?", (updated, room_id))
236+
# Old SOGS has a bug where it inserts duplicate deletion tombstones (see above), but
237+
# this means that our updated count might not be large enough for existing Session
238+
# clients to not break: they will be fetching deletion ids > X, but if we have 100
239+
# duplicates, the room's update counter would be X-100 and so existing clients
240+
# wouldn't actually fetch any new deletions until the counter catches up. Fix that
241+
# up by incrementing the updates counter if necessary.
242+
top_del_id = rconn.execute("SELECT MAX(id) FROM deleted_messages").fetchone()[0]
243+
244+
cur.execute(
245+
"UPDATE rooms SET updates = ? WHERE id = ?", (max(updated, top_del_id), room_id)
246+
)
237247

238248
# If we have to offset rowids then make sure the hack table exists and insert our
239249
# hack.

0 commit comments

Comments
 (0)