Repository navigation
fix(catalog): use semi-joins for discovery library scope - #88
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR refactors discovery query construction to centralize SQL generation and library-scoping logic via helper functions that return empty strings when access rules exclude all libraries, updates all three discovery recipes (rating-threshold, unplayed-high-rated, forgotten-favorites) to use semi-join EXISTS patterns for library filtering, and replaces tests with shared assertion helpers. It also updates the WHERE-clause filter for orphaned provisional media items. ChangesDiscovery Query Centralization
Orphaned Provisional Media Items Condition
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed8619c844
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| whereSQL, scopeArgs, ok := buildLibraryScopeJoin( | ||
| filter.AllowedLibraryIDs, | ||
| filter.DisabledLibraryIDs, | ||
| *argIdx, |
There was a problem hiding this comment.
Require membership for deny-only discovery filters
When a viewer has DisabledLibraryIDs but no allowlist, this new semi-join path calls buildLibraryScopeJoin(nil, disabled, ...), which emits only a NOT EXISTS against the disabled folders. That condition is true for media_items with no media_item_libraries rows, so orphan/stale rows can now appear in rating, unplayed, and forgotten-favorites discovery for users who merely disabled a library; the previous INNER JOIN shape excluded those rows, and ItemRepository.GetByIDsWithAccess explicitly preserves that positive-membership requirement for the same deny-only case.
Useful? React with 👍 / 👎.
* fix(catalog): use semi-joins for discovery library scope * fix(catalog): require membership for deny-only discovery
* fix(catalog): use semi-joins for discovery library scope * fix(catalog): require membership for deny-only discovery
Summary
mialias so library-scoped discovery queries no longer hit ambiguouscontent_idreferences.media_item_librariesjoins in discovery queries with the existingbuildLibraryScopeJoinsemi-join helper to avoid multi-library row fanout.Supersedes #80.
Root Cause
The discovery queries for hidden gems, critically acclaimed, and forgotten favorites could join
media_item_librariesfor library-scoped viewers while selecting the unqualifieditemColumnsprojection. Since bothmedia_itemsandmedia_item_librariesexposecontent_id, PostgreSQL can reject those queries withSQLSTATE 42702.The direct join form also fans out items that belong to multiple matching libraries, which can duplicate rows and interact badly with limits. The new shape keeps
media_items mias the only outer relation and scopes libraries withEXISTS/NOT EXISTSpredicates.Validation
go test ./internal/catalog -run 'Discovery|RatingThreshold|Unplayed|ForgottenFavorites|TestLateOrphanCleanupUsesProvisionalSafetyPredicate' -count=1go test ./internal/catalog -count=1git diff --check100.86.116.20:/api/v1/readyreturned OK.ERROR: column reference "content_id" is ambiguous.GET /api/v1/home/sectionsreturned 200 for a restricted profile.GET /api/v1/home/sections/127245166910046212/itemsreturned 200 forhidden_gems.SQLSTATE 42702, no ambiguouscontent_id, and no affected discovery fetch errors.EXISTSshape returned exactly one row per item.AI Use
Implemented with Codex.
Summary by CodeRabbit
Refactor
Tests