An open source, non-profit web search engine
Merge remote-tracking branch 'origin/main' into claude/admiring-mendel-yutoym
Claude98f7baf1f02c
diff --cc mwmbl/apps.pyindex c3f0df9,85630a4..f70b3e0--- a/mwmbl/apps.py+++ b/mwmbl/apps.py@@@ -158,7 -158,7 +159,8 @@@ class MwmblConfig(AppConfig)MODERATION_RETRAIN_TASK = "mwmbl.background.retrain_domain_moderation_model"INDEX_COUNT_TASK = "mwmbl.background.count_index_urls"FLUSH_TOKENS_TASK = "mwmbl.background.flush_expired_tokens"+ PRUNE_AGREEMENTS_TASK = "mwmbl.background.prune_crawler_agreements"+ SUMMARISE_CALLERS_TASK = "mwmbl.background.summarise_search_callers"# Sync search counts once per hour (3600 seconds)if not Task.objects.filter(task_name=SYNC_TASK).exists():@@@ -202,12 -202,10 +204,15 @@@# Clear expired refresh tokens out of the JWT blacklist tables once a dayif not Task.objects.filter(task_name=FLUSH_TOKENS_TASK).exists():flush_expired_tokens(repeat=Task.DAILY, repeat_until=None)++ if not Task.objects.filter(task_name=PRUNE_AGREEMENTS_TASK).exists():+ prune_crawler_agreements(repeat=Task.DAILY, repeat_until=None)+ # Hourly, so a finished week's per-caller counts are replaced by its totals well+ # inside the grace day before they expire - see mwmbl.search_callers.+ if not Task.objects.filter(task_name=SUMMARISE_CALLERS_TASK).exists():+ summarise_search_callers(repeat=Task.HOURLY, repeat_until=None)+except Exception:# Don't prevent startup if background task scheduling failslog.exception("Failed to schedule background tasks")diff --cc mwmbl/background.pyindex c159cf5,148f820..3be6966--- a/mwmbl/background.py+++ b/mwmbl/background.py@@@ -24,8 -23,9 +24,9 @@@ from django.core.management import callfrom django.db import transactionfrom redis import Redis-from mwmbl import pricing+from mwmbl import pricing, trafficfrom mwmbl.count_urls import count_urls_step, get_redis+ from mwmbl.crawler.agreement import prune_agreementsfrom mwmbl.crawler.stats import StatsManagerfrom mwmbl.indexer.blacklist_snapshot import get_snapshot_blacklist, refresh_snapshotfrom mwmbl.indexer.purge_blacklisted import purge_documents@@@ -359,8 -359,8 +360,15 @@@ def flush_expired_tokens()call_command("flushexpiredtokens")+ @background(schedule=0)+ def prune_crawler_agreements():+ """Delete crawler agreements older than their retention, since every shared URL adds a row."""+ deleted = prune_agreements()+ logger.info("Pruned %d crawler agreements", deleted)+++++@background(schedule=0)+def summarise_search_callers():+ """Roll last week's search callers into totals and delete the per-caller keys."""+ if traffic.summarise_last_caller_window(traffic.get_redis()):+ logger.info("Summarised last week's search callers")