Two-phase backlog scan with self-healing found-count tracking

Split each channel's backlog scan into a find phase (settles the
found count first) and a react phase, so the progress display no
longer grows both numbers in lockstep. Found messages are logged in
a dedicated, message_id-deduped table and recovered across restarts
independent of the resume checkpoint, so nothing found is silently
abandoned if the script stops mid-react.

Also drops the separately-maintained messages_found counter, which
proved prone to drift under repeated interruptions/rescans, in favor
of computing it live from the dedup table - self-healing regardless
of how many times a channel gets rescanned.
This commit is contained in:
2026-08-01 18:46:28 +02:00
parent 41b6b3f234
commit ab0afa149a
6 changed files with 136 additions and 32 deletions

View File

@@ -26,10 +26,18 @@ async def react_to_message(
emoji: str,
source: str,
display: Optional[StatsDisplay] = None,
count_found: bool = True,
) -> bool:
if message.author.id != friend_id:
return False
if count_found:
await asyncio.to_thread(
storage.record_message_found, message.id, message.channel.id, target.target_id, friend_id
)
if display is not None:
await display.refresh()
already_reacted = any(
reaction.me and str(reaction.emoji) == emoji for reaction in message.reactions
)