Private
Public Access
Stop retention from bringing deleted articles back (#29)
The nightly purge deleted articles, but a feed that still listed an entry would re-insert it on its next poll as a brand-new, unread article. For feeds with long archives, old items could reappear after every retention run. The purge now leaves a (feed, guid) tombstone per deleted article, and ingestion skips tombstoned guids. With retention on, entries whose own publish date is already outside the window are not ingested at all, so a long archive isn't fetched only to be purged and tombstoned the same night. Undated entries rely on the tombstone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
73dbee9400
commit
f8cd1eb33e
6 files changed
+156
-5
No files matched your search
+13
-3
@@ -1,6 +1,7 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from celery import shared_task
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.core.models import SiteSettings
|
||||
@@ -8,7 +9,7 @@ from apps.feeds.models import Subscription
|
||||
from apps.rules.engine import evaluate_rules_for_article
|
||||
from apps.rules.models import FilterRule
|
||||
|
||||
from .models import Article, ArticleTag, SubscriptionTag
|
||||
from .models import Article, ArticleTag, PurgedArticle, SubscriptionTag
|
||||
|
||||
|
||||
@shared_task
|
||||
@@ -75,6 +76,10 @@ def purge_old_articles():
|
||||
ArticleTag rows go with their article via ON DELETE CASCADE, and the
|
||||
SQLite FTS triggers drop the search entries. 0 days means keep
|
||||
everything forever (the default).
|
||||
|
||||
Each deleted article leaves a PurgedArticle tombstone first, so a feed
|
||||
that still lists the entry can't bring it back as a new, unread
|
||||
article on its next poll (see apps.feeds.services.fetcher).
|
||||
"""
|
||||
retention_days = SiteSettings.load().retention_days
|
||||
if retention_days <= 0:
|
||||
@@ -87,9 +92,14 @@ def purge_old_articles():
|
||||
chunk = list(
|
||||
Article.objects.filter(fetched_at__lt=cutoff)
|
||||
.exclude(pk__in=keep)
|
||||
.values_list("pk", flat=True)[:PURGE_CHUNK_SIZE]
|
||||
.values_list("pk", "feed_id", "guid")[:PURGE_CHUNK_SIZE]
|
||||
)
|
||||
if not chunk:
|
||||
return deleted_total
|
||||
Article.objects.filter(pk__in=chunk).delete()
|
||||
with transaction.atomic():
|
||||
PurgedArticle.objects.bulk_create(
|
||||
[PurgedArticle(feed_id=feed_id, guid=guid) for _pk, feed_id, guid in chunk],
|
||||
ignore_conflicts=True,
|
||||
)
|
||||
Article.objects.filter(pk__in=[pk for pk, _feed_id, _guid in chunk]).delete()
|
||||
deleted_total += len(chunk)
|
||||
Reference in new issue
Block a user