fix(packs): remove unfiltered pre-count in GET /packs (3 round-trips to 2) #211
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
autonomous
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
size:M
size:S
tech-debt
todo
type:feature
type:stability
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#211
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "autonomous/packs-remove-prefilter-count"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Autonomous pipeline work item
Finding: `GET /api/v2/packs` calls `Pack.select().count()` on the unfiltered table before applying filters, raising 404 if no packs exist globally. Correctness bug (wrong 404 on empty filter matches) + perf bug (extra DB round-trip per request).
Change: Remove the pre-filter count check at `routers_v2/packs.py:36-39`. Filtered queries now make 2 DB calls instead of 3, and empty filter matches return an empty result set instead of 404 (standard REST pattern). Also removed commented-out dead code block (lines 81-83) and added `# noqa: E711` to Peewee `== None` where-clauses (intentional ORM syntax for SQL IS NULL).
Verification:
Source: analyst-2026-04-10-008 (autonomous nightly run)
Remove Pack.select().count() on the unfiltered table at the top of GET /api/v2/packs. This check raised 404 if zero packs existed globally — wrong for filtered queries where no match is the expected empty-list result. The filtered count at the end of the handler already handles the empty-result case. Endpoint now returns {count: 0, packs: []} on empty filter matches (standard REST pattern) and saves one DB round-trip per request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>AI Code Review
Files Reviewed
app/routers_v2/packs.py(modified)Findings
Correctness
No issues found. The pre-filter count removal is the right fix:
Pack.select().count() == 0checked the entire unfiltered table; 404 raised when no packs existed globally — wrong response for a valid filtered request on an empty (or newly-seeded) table.{"count": 0, "packs": []}— standard REST pattern. ✅lines 81-83) correctly removed. ✅# noqa: E711onPack.pack_team == NoneandPack.pack_cardset == Noneis appropriate — Peewee ORM intentionally uses== Noneto generate SQLIS NULL, not an equality check. ✅Performance claim of 3 → 2 DB round-trips is accurate: old code did (1) unfiltered count + (2) filtered
.count()for response + (3) filtered iteration; new code does (1) filtered.count()+ (2) filtered iteration.Security
No issues found. No new inputs, no new query construction paths. Existing auth guards on write endpoints unchanged.
Style & Conventions
The diff includes ruff auto-reformatting throughout (single → double quotes, parameter list wrapping). Non-functional, consistent with project style. No CLAUDE.md violations.
Suggestions
GET /packswith no matching results returning{"count": 0, "packs": []}would close the gap.Verdict: COMMENT
No blocking issues. Self-review restriction applies (autonomous pipeline PR, single-repo author). Ready to merge.
Automated review by Claude PR Reviewer
fd377014dbto7f7d9ffe1f