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

12
main.py
View File

@@ -72,7 +72,7 @@ class ReactorClient(discord.Client):
async def react_fn(message: discord.Message, target: Target) -> bool:
return await react_to_message(
self.storage, message, target, self.cfg.friend_id, self.cfg.emoji,
source="backlog", display=self.display,
source="backlog", display=self.display, count_found=False,
)
for target in targets:
@@ -82,11 +82,17 @@ class ReactorClient(discord.Client):
log.warning("Channel %s (%s) not found in cache, skipping", target.target_id, target.name)
continue
self.known_channel_targets[channel.id] = target
await scan_channel_backlog(self.storage, channel, target, self.cfg.friend_id, cutoff, react_fn)
await scan_channel_backlog(
self.storage, channel, target, self.cfg.friend_id, self.cfg.emoji,
cutoff, react_fn, display=self.display,
)
else:
for channel in get_scannable_channels(self, target.target_id):
self.known_channel_targets[channel.id] = target
await scan_channel_backlog(self.storage, channel, target, self.cfg.friend_id, cutoff, react_fn)
await scan_channel_backlog(
self.storage, channel, target, self.cfg.friend_id, self.cfg.emoji,
cutoff, react_fn, display=self.display,
)
log.info("Backlog scan complete. Now watching live.")