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

@@ -4,6 +4,7 @@ from typing import List, Optional
from rich.console import Console
from rich.live import Live
from rich.panel import Panel
from rich.progress_bar import ProgressBar
from rich.table import Table
from bot.storage import Storage
@@ -15,24 +16,32 @@ def _render(stats: List[dict], friend_label: Optional[str] = None) -> Panel:
table = Table(expand=True)
table.add_column("Target")
table.add_column("Type")
table.add_column("Reactions", justify="right")
table.add_column("Progress", ratio=1)
table.add_column("Reacted/Found", justify="right")
table.add_column("Last reaction (UTC)")
total = 0
total_reacted = 0
total_found = 0
for row in stats:
total += row["reaction_count"]
reacted = row["reaction_count"]
found = max(row["messages_found"], reacted) # found can never be less than reacted
total_reacted += reacted
total_found += found
bar = ProgressBar(total=max(found, reacted, 1), completed=reacted, width=None)
table.add_row(
row["name"] or row["target_id"],
_TYPE_LABELS.get(row["target_type"], row["target_type"]),
str(row["reaction_count"]),
bar,
f"{reacted}/{found}",
row["last_reaction_at"] or "-",
)
if not stats:
table.add_row("(no targets discovered yet)", "-", "-", "-")
table.add_row("(no targets discovered yet)", "-", "-", "-", "-")
who = f" for {friend_label}" if friend_label else ""
return Panel(table, title=f"Reaction stats{who} — total: {total}", border_style="cyan")
return Panel(table, title=f"Reaction stats{who} — total: {total_reacted}/{total_found}", border_style="cyan")
class StatsDisplay: