From 8b8b0ca5ab79d67da1c8455b31e867bda7184c01 Mon Sep 17 00:00:00 2001 From: npeter83 Date: Tue, 18 Aug 2026 16:49:29 +0200 Subject: [PATCH] perf(feed): skip the empty IN() query in tags_by_category (E2 review round 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tags_by_category extraction dropped feed_summary's `if selected:` guard, so a /feed/summary request with no tag filter (the common case) ran a pointless `SELECT ... WHERE id IN ()` round-trip. Early-return {} for empty tag_ids — restores the no-query hot path and covers filtered_query + future callers too. Gate green (346 pytest). --- backend/app/feedquery.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/app/feedquery.py b/backend/app/feedquery.py index 9fcdca4c..2703583e 100644 --- a/backend/app/feedquery.py +++ b/backend/app/feedquery.py @@ -104,6 +104,8 @@ def tags_by_category(db: Session, tag_ids: list[int]) -> dict[str, list[int]]: """Group tag ids by their category (language/topic/other). The single source for the category split shared by the feed's tag WHERE (filtered_query) and the facet/count summary (feed_summary), so the two can't disagree on which selected tag belongs to which category.""" + if not tag_ids: + return {} # skip the pointless `WHERE id IN ()` round-trip on the no-tag-filter hot path out: dict[str, list[int]] = {} for tid, cat in db.execute(select(Tag.id, Tag.category).where(Tag.id.in_(tag_ids))).all(): out.setdefault(cat, []).append(tid)