Add the filter/rules engine

Implements FilterRule (one condition -> action, scoped to a feed and/or
folder or global) with an evaluation engine applied at ingest time:
after the fetch pipeline commits new/updated articles, each affected
subscriber's enabled rules run in priority order against them, with
tag/star/mark_read actions stacking and hide short-circuiting further
evaluation for that article.

Adds rule management (create/edit/delete) and a "Re-apply" action that
re-evaluates a user's full ruleset against their unread backlog, scoped
by the triggering rule's own feed/folder — so a newly added rule can
retroactively affect already-ingested articles, not just future ones.

Verified live in-browser: created a "title contains 'Show HN' -> star"
rule scoped to the subscribed Hacker News feed, re-applied it against
the existing unread backlog, and confirmed both matching articles were
starred.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5 committed 2026-10-30 16:31:33 -06:00
1 parent 579696efc0
commit 5ed0499845
18 files changed
+1072 -6

No files matched your search

+5 -3
View File
@@ -4,6 +4,8 @@ from datetime import timedelta
from celery import shared_task
from django.utils import timezone
from apps.articles.tasks import apply_filter_rules_for_feed
from .models import Feed
from .services.fetcher import effective_interval_minutes, fetch_and_ingest
@@ -45,15 +47,15 @@ def fetch_feed(feed_id: int):
result = fetch_and_ingest(feed)
feed.save()
if result.new_article_ids:
changed_article_ids = result.new_article_ids + result.updated_article_ids
if changed_article_ids:
logger.info(
"Feed %s: %d new article(s), %d updated",
feed.feed_url,
len(result.new_article_ids),
len(result.updated_article_ids),
)
# Rule application (tag/star/hide/mark_read on new articles for each
# subscriber) is wired in once apps.rules exists — see milestone 6.
apply_filter_rules_for_feed.delay(feed_id, changed_article_ids)
return {
"status": result.status,