email: live backfill progress on Email Capture panel — v0.1.0:61

The first Gmail backfill leaves the account at "pending · never synced" until it
fully completes (the sync_runs row only finalizes at the end), so there was no
feedback. /api/email/status now also returns captured_emails (total, which climbs
page-by-page during backfill), the latest sync run, and a backfilling flag. The
panel shows a "Backfilling… N captured so far" banner + an Emails Captured count
and auto-refreshes every 5s while a backfill is in progress. Verified live in
preview with seeded data (count auto-climbed 37 -> 50 without manual refresh).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Keysat
2026-06-06 12:29:01 -05:00
parent 1850bc4431
commit 2cb476e36b
5 changed files with 60 additions and 12 deletions
+12
View File
@@ -131,6 +131,18 @@ def _h_status(handler):
counts = dict(cur.fetchone() or {})
cur.execute("SELECT COUNT(*) AS n FROM emails WHERE match_status = 'matched'")
snap["matched_emails"] = cur.fetchone()["n"]
# Total captured climbs page-by-page during backfill (the sync_runs row only
# finalizes at the end), so it is the live progress signal.
cur.execute("SELECT COUNT(*) AS n FROM emails")
snap["captured_emails"] = cur.fetchone()["n"]
# Latest sync run (status running|ok|error|partial) for a human-readable line.
cur.execute("SELECT kind, status, started_at, finished_at, messages_seen, messages_stored "
"FROM email_sync_runs ORDER BY started_at DESC LIMIT 1")
lr = cur.fetchone()
snap["last_run"] = dict(lr) if lr else None
# An enrolled account whose backfill has not completed is still pulling history.
cur.execute("SELECT COUNT(*) AS n FROM email_accounts WHERE sync_enabled = 1 AND backfill_complete = 0")
snap["backfilling"] = (cur.fetchone()["n"] or 0) > 0
finally:
conn.close()
snap["accounts_summary"] = counts