Skip to content

Commit 4541bf8

Browse files
authored
Merge pull request #16 from jagerman/migration-deletion-fix
Fix missing deletion bug
2 parents 7532bae + 1de05e5 commit 4541bf8

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)