Repository navigation
fix(catalog): resolve episode-scoped history to episode-level items - #307
Conversation
The History page's "Episodes" media filter was structurally empty: both history read paths collapse episode watch events into their series display item, and the resulting series ids were then filtered against type='episode' — guaranteed zero results. The episode media scope now resolves history at episode granularity: - loadPersonalSourceIDs keeps each watched episode's own id (deduped to the most recent watch, most-recent-first) instead of collapsing to the series; ListFilters and SearchFacet share the loader, so facets on the episode-scoped history view work too. - fetchAccessibleItemsByID gains an episode-scope path through the episode catalog query executor, since episode rows never hydrate from media_items via the browse repository. Every other scope keeps the existing series-collapse behavior. Fixes #299 Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughThe catalog resolver now distinguishes episode-scoped history requests, returning episode-level IDs via a new ChangesEpisode-scope history resolution
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant CatalogResolver
participant HistoryDisplay
participant QueryExecutor
User->>CatalogResolver: CatalogRequest(Source=History, MediaScope=episode)
CatalogResolver->>HistoryDisplay: HistoryEpisodeScopeIDs(watchHistoryEntries)
HistoryDisplay-->>CatalogResolver: deduplicated episode content IDs
CatalogResolver->>CatalogResolver: fetchAccessibleItemsByID(episode scope)
CatalogResolver->>CatalogResolver: fetchAccessibleEpisodeItemsByID(contentIDs, allowedIDs)
CatalogResolver->>QueryExecutor: query filtered by intersected content IDs
QueryExecutor-->>CatalogResolver: hydrated episode media items
CatalogResolver->>CatalogResolver: reorder items to match requested ID order
CatalogResolver-->>User: ordered episode-scoped results
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/catalog/history_display.go (1)
16-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor duplication with
ResolveHistoryDisplayIDs.The trim/skip-empty/dedupe loop here is structurally the same as the one in
ResolveHistoryDisplayIDs(lines 64-79), differing only by the series-ID remap step. Could extract a small shared helper (e.g.dedupeTrimmedIDs(entries, remap func(string) string)) to avoid maintaining two copies of the same dedup logic.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/catalog/history_display.go` around lines 16 - 31, The trim/skip-empty/dedupe logic in HistoryEpisodeScopeIDs is duplicated from ResolveHistoryDisplayIDs; extract a small shared helper to centralize it. Refactor the repeated loop in HistoryEpisodeScopeIDs and ResolveHistoryDisplayIDs into a common helper such as dedupeTrimmedIDs that handles trimming, empty filtering, and deduping, with ResolveHistoryDisplayIDs passing its remap behavior separately.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/catalog/history_display.go`:
- Around line 16-31: The trim/skip-empty/dedupe logic in HistoryEpisodeScopeIDs
is duplicated from ResolveHistoryDisplayIDs; extract a small shared helper to
centralize it. Refactor the repeated loop in HistoryEpisodeScopeIDs and
ResolveHistoryDisplayIDs into a common helper such as dedupeTrimmedIDs that
handles trimming, empty filtering, and deduping, with ResolveHistoryDisplayIDs
passing its remap behavior separately.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f71a8473-9267-4dbc-a101-b6f50c6e22cc
📒 Files selected for processing (4)
internal/catalog/catalog_resolver.gointernal/catalog/history_display.gointernal/catalog/history_display_test.gointernal/catalog/history_episode_scope_db_test.go
…ilo-Server#307) The History page's "Episodes" media filter was structurally empty: both history read paths collapse episode watch events into their series display item, and the resulting series ids were then filtered against type='episode' — guaranteed zero results. The episode media scope now resolves history at episode granularity: - loadPersonalSourceIDs keeps each watched episode's own id (deduped to the most recent watch, most-recent-first) instead of collapsing to the series; ListFilters and SearchFacet share the loader, so facets on the episode-scoped history view work too. - fetchAccessibleItemsByID gains an episode-scope path through the episode catalog query executor, since episode rows never hydrate from media_items via the browse repository. Every other scope keeps the existing series-collapse behavior. Fixes Silo-Server#299 Co-authored-by: Claude Fable 5 <[email protected]>
Problem
The History page's "Episodes" media filter always returned 0 RESULTS, even immediately after watching an episode to completion (#299, reported via an internal Discord thread). The write path was fine — the bug was on the read side: both history read paths collapse episode watch events into their series display item, and the resulting series ids were then filtered against
media_items.type='episode', which is structurally guaranteed to match nothing.Approach
Per the direction chosen on the issue, the episode media scope now resolves history at episode granularity rather than hiding the option:
loadPersonalSourceIDskeeps each watched episode's own content id when the episode scope is selected — deduplicated to the most recent watch, preserving most-recent-first order. Every other scope keeps the existing series-collapse behavior. BecauseListFiltersandSearchFacetshare this loader, filter facets on the episode-scoped history view become consistent too.fetchAccessibleEpisodeItemsByID: episode rows don't exist inmedia_items, so the browse-repository hydration path can never return them. Episode-scoped id fetches now go through the episode catalog query executor (the same relation library episode browsing uses), intersecting with any pre-set allowed-content restriction and preserving source order.No web changes needed: the "Episodes" option is already offered on the History page,
ItemCardalready renders episode labels, and history removal already accepts episode content ids with scopeitem.Verification
TestHistoryEpisodeScopeIDs— pure unit test for the dedup/ordering helper.TestResolveHistoryEpisodeScope— DB-backed end-to-end test: seeds a series, two episodes, and watch history; asserts the episode scope returns both episodes most-recent-first withtype=episode, and that the unscoped view still collapses to a single series item. Passes against a freshly migrated scratch database, along with the fullinternal/catalogsuite in DB-backed mode.gofmt,go vet, andgolangci-lintclean on changed lines.Risks / follow-up
/api/v1: no fields renamed or removed; a previously (wrongly) empty result set now returns data.Fixes #299
AI-use disclosure
Implemented by Claude Code (Claude Fable 5) with human review.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes