Private
Public Access
Batch rule/tag lookups and index FilterRule for the ingest query (C9)
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>
This commit is contained in:
1 parent
abf4cef55b
commit
cb0ce5a336
4 files changed
+91
-11
No files matched your search
@@ -75,6 +75,16 @@ class FilterRule(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ["priority", "id"]
|
||||
indexes = [
|
||||
# Matches the ingest-time query shape exactly (C9): every
|
||||
# caller — apps.articles.tasks.apply_filter_rules_for_feed,
|
||||
# apps.rules.tasks.reapply_rules_for_user_backlog — filters by
|
||||
# (user, is_enabled) and orders by priority. `user` alone
|
||||
# already has an index from the ForeignKey, but it doesn't
|
||||
# cover is_enabled or let the database satisfy the ORDER BY
|
||||
# from the index itself.
|
||||
models.Index(fields=["user", "is_enabled", "priority"]),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
label = self.name or f"{self.get_match_field_display()} {self.get_match_type_display()}"
|
||||
|
||||
Reference in new issue
Block a user