Fix races and stale things

This commit is contained in:
Jack Kingsman
2026-04-10 15:54:03 -07:00
parent 59601bb98e
commit 4f19e1ec9a
3 changed files with 16 additions and 8 deletions
+4 -3
View File
@@ -557,10 +557,11 @@ class MessageRepository:
@staticmethod
async def increment_ack_count(message_id: int) -> int:
"""Increment ack count and return the new value."""
await db.conn.execute("UPDATE messages SET acked = acked + 1 WHERE id = ?", (message_id,))
await db.conn.commit()
cursor = await db.conn.execute("SELECT acked FROM messages WHERE id = ?", (message_id,))
cursor = await db.conn.execute(
"UPDATE messages SET acked = acked + 1 WHERE id = ? RETURNING acked", (message_id,)
)
row = await cursor.fetchone()
await db.conn.commit()
return row["acked"] if row else 1
@staticmethod