Skip to content

fix(catalog): resolve episode-scoped history to episode-level items - #307

Merged
Quick104 merged 1 commit into
mainfrom
claude/agitated-margulis-931ce7
Jul 5, 2026
Merged

Quick104 merged 1 commit into
mainfrom
claude/agitated-margulis-931ce7

Conversation

@Quick104

@Quick104 Quick104 commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • loadPersonalSourceIDs keeps 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. Because ListFilters and SearchFacet share this loader, filter facets on the episode-scoped history view become consistent too.
  • New fetchAccessibleEpisodeItemsByID: episode rows don't exist in media_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, ItemCard already renders episode labels, and history removal already accepts episode content ids with scope item.

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 with type=episode, and that the unscoped view still collapses to a single series item. Passes against a freshly migrated scratch database, along with the full internal/catalog suite in DB-backed mode.
  • gofmt, go vet, and golangci-lint clean on changed lines.

Risks / follow-up

  • Additive only within /api/v1: no fields renamed or removed; a previously (wrongly) empty result set now returns data.
  • Not addressed here: the data-dependent "blank even unfiltered" variant from orphaned legacy episode ids (the unscoped view's INNER JOIN still silently drops history rows whose episode can't resolve to a series). That's a separate resilience/backfill decision.

Fixes #299

AI-use disclosure

Implemented by Claude Code (Claude Fable 5) with human review.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • History results can now be viewed at episode granularity, preserving episode order and returning episode-level items when requested.
    • Item hydration now respects episode-scoped requests, improving consistency for episode-based browsing and history views.
  • Bug Fixes

    • Fixed duplicate or blank history entries from appearing in episode-scoped results.
    • Improved result ordering so hydrated items match the original requested order.

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]>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The catalog resolver now distinguishes episode-scoped history requests, returning episode-level IDs via a new HistoryEpisodeScopeIDs helper instead of collapsing to series IDs. A new hydration path, fetchAccessibleEpisodeItemsByID, resolves these IDs directly. Unit and database integration tests validate the behavior.

Changes

Episode-scope history resolution

Layer / File(s) Summary
Episode-scope history ID generation
internal/catalog/history_display.go, internal/catalog/history_display_test.go
Adds HistoryEpisodeScopeIDs, which trims and deduplicates MediaItemID values from watch history entries, skipping blanks; unit tests cover dedup/trim behavior and empty input.
Resolver routing for episode scope
internal/catalog/catalog_resolver.go
Personal history resolution returns episode-scoped IDs instead of series IDs when episode media scope is requested; fetchAccessibleItemsByID redirects episode-scope requests to a new hydration function.
Episode-specific content ID hydration
internal/catalog/catalog_resolver.go
Adds fetchAccessibleEpisodeItemsByID, hydrating items via the query executor using requested content IDs intersected with allowed IDs, preserving original order; adds intersectContentIDs helper.
Database integration test for episode-scope resolution
internal/catalog/history_episode_scope_db_test.go
Seeds a series, two episodes, and watch-history rows in Postgres, then verifies episode-scope resolution returns ordered episode items while unscoped resolution collapses to the series item.

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
Loading

Suggested labels: v1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: resolving history at episode granularity for episode-scoped views.
Linked Issues check ✅ Passed The PR implements the requested fix by returning episode-level history IDs and hydrating them through the episode path, matching issue #299.
Out of Scope Changes check ✅ Passed The added helper, resolver changes, and tests all support the episode-scoped history fix and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/agitated-margulis-931ce7

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 5, 2026
@Quick104
Quick104 merged commit 38bf701 into main Jul 5, 2026
1 check was pending
@Quick104
Quick104 deleted the claude/agitated-margulis-931ce7 branch July 5, 2026 16:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/catalog/history_display.go (1)

16-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor 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

📥 Commits

Reviewing files that changed from the base of the PR and between e5379cd and 79ff523.

📒 Files selected for processing (4)
  • internal/catalog/catalog_resolver.go
  • internal/catalog/history_display.go
  • internal/catalog/history_display_test.go
  • internal/catalog/history_episode_scope_db_test.go

Quick104 added a commit to RXWatcher/silo-server that referenced this pull request Jul 10, 2026
…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]>
@zZebrahz zZebrahz mentioned this pull request Sep 27, 2026
10 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

History page 'Episodes' filter is structurally empty (episode rows collapse to series, then get type-filtered)

1 participant