Repository navigation
Conversation
Recently Added TV grouped new episodes by the scan run that found them. Sonarr and other arr tools send one webhook per imported episode, and each becomes its own scan run, so a backfilled season showed up as one card per episode. Group a show's arrivals by time instead: an episode first seen within 2 hours of the show's previous arrival joins that group. A one-episode group is an episode card and a larger group is the series card. The home row now groups only the full history of shows with a recent arrival, widening the window until it has enough cards and falling back to the full query. Its total_count becomes a lower bound.
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughRecently Added TV events now group episodes by chained arrival times. The home-row path uses a bounded query with a full-query fallback, and reports ChangesRecently Added TV arrivals
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant Fetcher
participant ListNewest as RecentTVRepository.ListNewest
participant List as RecentTVRepository.List
participant Database
Fetcher->>ListNewest: Request newest unique targets
ListNewest->>Database: Query bounded arrival window
Database-->>ListNewest: Return window results
alt bounded window needs fallback
ListNewest->>List: Request unique targets
List->>Database: Query full recent-TV events
Database-->>List: Return targets and hasMore
List-->>ListNewest: Return full-query results
end
ListNewest-->>Fetcher: Return targets and hasMore
Suggested reviewers: Merge Risk: 🟡 Moderate · up to Some libraries may see slower Recently Added TV catalog pages and fallback home loads, although the usual open-profile home row is reported to be faster. Resolve or accept that tradeoff before merging. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 2 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The cases named in the Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Quick104
left a comment
There was a problem hiding this comment.
Two findings. The performance one is inline and needs your call. The other is below.
Low, comment drift: three comments outside the diff still say Recently Added TV makes one card per scan-run event. They are in internal/catalog/playable_targets.go (PlayableTargetInput.Key), internal/api/handlers/items.go (playableTargetInputForItem), and internal/jellycompat/handlers_items.go (loadLatestViaSections). What they describe still holds: a show can appear on two cards with different anchors, and /Items/Latest opts out of the grouping. But the cause is now arrival events, and the repository treats a comment that disagrees with the code as wrong. I'm fixing this in a commit on this branch, so there's no need to change it yourself.
I also checked these and found no problems:
ListNewestagainst the full query: 25 random seeds with forced timestamp ties, arrivals exactly 2 hours apart, episodes in two folders, missing files, shows with no episodes, and open, half, and single-show allow-lists. Bounded and fallback results matched, including event IDs and play anchors.- Full cursor walks for both unique and per-event listings.
- How web, Apple, and Android use
total_count. They only adjust it on Continue Watching and Next Up, or compare it withitem_limitor zero.
Review by Claude Code (claude-opus-5-5).
| return targets, false, err | ||
| } | ||
| q.UniqueTargets, q.SkipTotal = true, true | ||
| targets, _, hasMore, err := r.List(ctx, q) |
There was a problem hiding this comment.
Needs your call (medium, performance): on episodes with no scan-run record, the full query is about 2.5× slower than on main.
Episodes first seen before scan-run tracking existed have a NULL first_seen_scan_run_id. On main, all of a show's NULL rows become one event, so those shows are cheap to group. This PR splits the same rows at every gap longer than 2 hours. For a show that gets one episode a week, that means one event per episode. That's the grouping the PR is after, but it costs more, and most existing libraries are largely made of such rows.
I seeded a synthetic library of 5,000 shows and 200,000 episodes and ran both trees against the same database. Each figure is the median of 7 runs:
| Query | No scan-run IDs: main |
No scan-run IDs: this PR | One scan run per episode: main |
One scan run per episode: this PR |
|---|---|---|---|---|
| Home row, open profile | 304 ms | 23 ms | 880 ms | 15 ms |
| Home row, profile allowed 20 shows (falls back here) | 318 ms | 832 ms | 630 ms | 749 ms |
| Catalog view, cursor page | 309 ms | 872 ms | 831 ms | 822 ms |
| Catalog view, name prefix | 342 ms | 751 ms | 305 ms | 662 ms |
The open home row gets much faster either way. On libraries without scan-run IDs, three paths get about 2.5× slower:
- the home row for profiles whose visible arrivals are too sparse to fill the 8,192-row window;
- the first home load after a bulk import;
- the catalog "View all" page.
The description's "within about 15% of main" and "~275 ms vs ~285 ms" figures match the case where episodes carry scan-run IDs. I also measured name-prefix search as slower in both cases, not faster.
Options:
- Accept the cost and correct the performance section of the description so it covers episodes without scan-run IDs.
- Keep restricted profiles on the bounded path: have the cutoff probe count only arrivals from shows the caller can see, so the window doesn't hit 8,192 rows and fall back. With an allow-list, the probe could read the allowed shows through
episodes(series_id)instead of the folder index. - Serve the catalog view's
skip_totalcursor pages through the same cutoff approach, and keep the full query for exact totals.
I'm not changing this. It's a tradeoff for you and the maintainers.
Three comments still said Recently Added TV keeps one card per scan-run event. Cards now come from arrival events, so say that. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Providing Context (Files & MCPs)Add these hints in your PR description (or a comment) to unlock deeper checks:
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
Review summaryReviewed head: Addressed
Still open
Verified
Validated features: unaffected. The passed cases on the v1.0 board cover API keys, admin impersonation, Calendar, person browsing, and user management, and none of them reaches Recently Added TV or the home sections. Validation status: CI on Mergeability: 7/10 — conditional. The grouping is correct and well tested, and the open home row gets much faster. Two conditions remain: a decision on the slowdown for episodes without scan-run IDs, with the description updated to match, and green CI on the new head. Review by Claude Code (claude-opus-5-5). |
Main now holds #1697 as a squash commit, so this carries only this branch's own changes onto it. It also regenerates the v2 OpenAPI artifact, web types and contract fixtures, which went stale on main when #1697 merged after #1710 and #1731. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Problem
Related issue: #1588
Validation tasks: none
Recently Added TV groups new episodes by the scan run that found them (#561). Sonarr and other arr tools send one webhook per imported episode, and each webhook becomes its own scan run, so every episode ends up in its own group. A backfilled season fills the home row with one card per episode of the same show.
This change groups by arrival time instead. An episode first seen within 2 hours of the show's previous arrival joins that group, so a trickle of imports stays one group even when it spans more than 2 hours. A group with one episode is still an episode card. A larger group is the series card, placed by its newest episode. Webhook imports, polling sources, and library scans all group the same way. Episodes added before scan runs were tracked now group this way too; before, they were always series cards.
This PR does not add the per-library or per-profile grouping setting, or the new response fields, proposed in #1588.
Approach
first_seen_at, starts a new group after any gap longer than 2 hours. Scan-run provenance is still recorded but no longer read here. In catalog cursors, the group's start time replaces the scan-run ID as the event identity.mainand with time grouping alone. The home row now usesListNewest. It takes the Nth newest arrival as a cutoff and groups the full history of every show with an arrival since then. Any group newer than the cutoff belongs to one of those shows, so the result matches the full query. If that gives too few cards, the cutoff moves back. Past 8,192 arrivals, which usually means right after a bulk import, it falls back to the full query. The query runs withSET LOCAL jit = off, because the planner overestimates its cost enough to trigger JIT, and compiling took longer than running it.total_count. On the home row,total_countis now a lower bound: the cards returned, plus one when more exist. It used to be an exact count of every group. The v2 contract already documents it as "at least the number returned", and web, Apple, and Android only compare it with the item limit or with zero. The catalog view still reports the exact count.Home row on the synthetic library:
mainwork_memwork_mem32 MBThe catalog view keeps the full query. It runs within about 15% of
main: cursor paging is slightly slower, and name-prefix search is faster.Validation
gofmt,go vet, andmake lint-changed: clean.ListNewestwith the full query across randomized arrival patterns, limits, libraries, and access filters, plus a case where the cutoff falls inside a group. Sections tests also pass.make test-db-pins: 25 of 25 pass.verify-apiv2-openapi,verify-apiv2-contract,verify-route-inventory,verify-migration-ledger, andverify-local-paths: pass.make test-go:TestAdminResourceCapabilitiesAndScopeininternal/apiv2and the hardware-probe tests ininternal/playbackfail. They fail the same way onmainin this environment. Theinternal/jellycompattranscode tests failed in the full parallel run and pass when run alone.Risks
total_countas a number would now show a smaller one. None of the first-party clients do./Items/Latestendpoint turns this grouping off and is unaffected.Checklist
AI Disclosure
total_countchange. None found a material issue. The only change was one outdated code comment. A deliberate mutation, grouping only the rows after the cutoff, confirmed that the new cutoff test fails when it should.Note
Group recently added TV by arrival time instead of scan-run identity
catalog.RecentTVRepository.ListNewestanswers home-row queries from progressively larger bounded recent-arrival windows and falls back to the full unique-target query when a window cannot answer. fetcher.go now uses it, reportingtotal_countas page length plus one when more cards exist, instead of an exact count.first_seen_scan_run_idare now keyed by arrival time, so existing event identities change; home-rowtotal_countfor recently added TV is a lower bound, not an exact total (documented in catalog-api.md).Macroscope summarized ed5c43d.