email: per-mailbox captured/matched counts on Email Capture (v0.1.0:65)
/api/email/accounts now returns captured + matched per account (from the per-mailbox sighting table email_account_messages joined to emails; emails dedupe globally so an email seen by two mailboxes counts for each). Each mailbox card on the Email Capture page shows "<N> captured · <M> matched" so per-user coverage is visible, not just the aggregate. Verified in preview with two seeded mailboxes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -162,6 +162,22 @@ def _h_list_accounts(handler):
|
||||
"FROM email_accounts ORDER BY email_address"
|
||||
)
|
||||
rows = [dict(r) for r in cur.fetchall()]
|
||||
# Per-mailbox counts: emails are de-duplicated globally, so "captured per
|
||||
# mailbox" comes from the per-account sighting table; "matched" joins to emails.
|
||||
captured, matched = {}, {}
|
||||
try:
|
||||
captured = {r["account_id"]: r["n"] for r in cur.execute(
|
||||
"SELECT account_id, COUNT(*) AS n FROM email_account_messages "
|
||||
"WHERE deleted_at IS NULL GROUP BY account_id")}
|
||||
matched = {r["account_id"]: r["n"] for r in cur.execute(
|
||||
"SELECT eam.account_id AS account_id, COUNT(*) AS n FROM email_account_messages eam "
|
||||
"JOIN emails e ON e.id = eam.email_id "
|
||||
"WHERE eam.deleted_at IS NULL AND e.is_matched = 1 GROUP BY eam.account_id")}
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
for r in rows:
|
||||
r["captured"] = captured.get(r["id"], 0)
|
||||
r["matched"] = matched.get(r["id"], 0)
|
||||
finally:
|
||||
conn.close()
|
||||
# Non-admins only see their own row
|
||||
|
||||
Reference in New Issue
Block a user