Private
Public Access
FilterRule had no indexes beyond the default primary/foreign-key ones, and apply_filter_rules_for_feed issued 2 queries per subscriber (its enabled rules, its subscription tags) inside a loop over every subscriber of the feed — both cost grew with subscriber/rule count on every single feed poll. Adds a composite index on (user, is_enabled, priority), matching the exact filter+order shape every caller already uses (this task, apps.rules.tasks' backlog re-apply). apply_filter_rules_for_feed now fetches rules and subscription tags once for the whole feed's subscriber set, grouped by user/subscription in Python, instead of once per subscriber. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>