scheduler: process newest UIDs first to prioritize fresh mail

The per-rule batch was sliced from all_uids in server order (oldest
UID first), so with a big backlog the scheduler chewed through years
of unmatched newsletters before reaching the current invoices the
user was actually waiting on. Sort new_uids descending by int (with a
plain reverse() fallback for non-numeric UIDs) so each poll picks the
newest 500 first. Old backlog still gets worked off in the background.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-01 12:04:12 +02:00
co-authored by Claude Opus 4.7
parent e73d90747b
commit a38b8ce8c1
+8
View File
@@ -115,7 +115,15 @@ def _poll_account_sync(account_id: int) -> None:
.all()
)
# Neueste UIDs zuerst — sonst arbeitet der Scheduler bei großem
# Backlog erst durch Jahre alte Newsletter, bevor er aktuelle
# Rechnungen erreicht. UIDs sind auf IMAP-Servern monoton
# steigend, daher sortiert reverse-int zuverlässig neu→alt.
new_uids = [uid for uid in all_uids if uid not in processed_uids]
try:
new_uids.sort(key=int, reverse=True)
except (ValueError, TypeError):
new_uids.reverse()
if not new_uids:
write_log(