Skip to content

fix(rules): scope exclusion cascade by type, not entry point (#2858)#2867

Merged
enoch85 merged 1 commit into
developmentfrom
fix/2858-exclusion-cascade-by-type
May 10, 2026
Merged

fix(rules): scope exclusion cascade by type, not entry point (#2858)#2867
enoch85 merged 1 commit into
developmentfrom
fix/2858-exclusion-cascade-by-type

Conversation

@enoch85

@enoch85 enoch85 commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2858. Excluding a single episode skipped every other episode of the same show.

The cascade filter in handleCollection and syncManualMediaServerToCollectionDB keyed off Exclusion.parent, but parent is the entry point of the exclusion request — setExclusion writes parent: data.mediaId, and from the AddModal opened on a show overview that's always the show id, regardless of whether the user is excluding the show, a season, or one episode. So a single-episode exclusion landed with parent=showId, and any other episode of that show matched via grandparentId.

Cascade is now driven by Exclusion.type + Exclusion.mediaServerId via a small helper (buildExclusionCascadeSets / isMediaItemExcluded). A type='show' row cascades to its seasons and episodes; a type='season' row cascades to its episodes; episode/movie rows do not cascade. Legacy null-type rows fall back to the pre-existing parent-based cascade so we don't regress users whose ExclusionTypeCorrectorService backfill hasn't yet completed.

Both handleCollection and syncManualMediaServerToCollectionDB now go through the helper, removing two copies of the same buggy filter.

Excluding a single episode used to skip every other episode of the same
show. The cascade filter keyed off `Exclusion.parent`, but `parent` is the
entry point of the exclusion request (set to `data.mediaId`, which from the
show overview is always the show id) — not the structural parent. A typed
cascade set driven by `mediaServerId` of `type='show'`/`'season'` rows fixes
the regression without breaking the legacy null-type fallback.
@enoch85 enoch85 merged commit f4b161d into development May 10, 2026
13 checks passed
@enoch85 enoch85 deleted the fix/2858-exclusion-cascade-by-type branch May 10, 2026 16:51
maintainerr-automation Bot added a commit that referenced this pull request May 11, 2026
* docs: sync overlay processing API and add UI test-utils reference (#2866)

Documents the force flag on overlay processing endpoints and the 409
gating on DELETE /overlays/reset (#2827), and points contributors at
the new TanStack Query test helpers (#2863).

* fix(rules): scope exclusion cascade by type, not entry point (#2858) (#2867)

Excluding a single episode used to skip every other episode of the same
show. The cascade filter keyed off `Exclusion.parent`, but `parent` is the
entry point of the exclusion request (set to `data.mediaId`, which from the
show overview is always the show id) — not the structural parent. A typed
cascade set driven by `mediaServerId` of `type='show'`/`'season'` rows fixes
the regression without breaking the legacy null-type fallback.

* fix(collections): sort by addDate and group episodes by show (#2868)

* fix(collections): sort by addDate and group episodes by show

Maintainerr is now the source of truth for collection ordering: both the
Plex push and the UI fetch use the same comparator, so what users see in
the collection page matches what the media server displays.

- deleteSoonest now reads collection_media.addDate (drives the visible
  "Leaving in X days" overlay) instead of MediaItem.addedAt (the
  unrelated media-server library date)
- Same-day items tie via UTC day bucketing so the title tiebreaker
  actually fires within a "Leaving Today" group
- Title sort groups episodes/seasons under their show via
  grandparentTitle/parentTitle; movies are unaffected

* refactor(sort): pin missing values to end + DRY numeric branches

- Items missing the sort value (no air date, no rating, no view count, no
  add date) now sort to the end regardless of asc/desc. Previously they
  coerced to 0 and silently sorted to the front in ascending order — an
  item with no air date appeared before one from 1995.
- airDate, rating, watchCount, and deleteSoonest collapse onto one helper
  (compareNumericWithTitleFallback), removing three near-identical case
  bodies in compareMediaItemsBySort.
- airDate now day-buckets like deleteSoonest, so same-day items always
  reach the title tiebreaker instead of comparing by clock time.
- Pin tsBuildInfoFile in apps/server/tsconfig.build.json so nest-cli's
  type-check pass stops emitting a stray tsconfig.build.tsbuildinfo at
  the package root.

* refactor(sort): align deleteSoonest buckets with visible daysLeft

- Bucket deleteSoonest by `ceil((addDate - referenceTime) / dayMs)` so
  items showing the same "Leaving in X days" countdown tie even when
  their addDates straddle UTC midnight. Falls back to UTC-day bucketing
  when no reference time is supplied.
- Wire `referenceTime = now - deleteAfterDays * dayMs` through the two
  collection sort paths (applyCollectionSort + paginated fetch).
- Replace the show-aware title test data — old data alphabetized
  identically under either comparator and didn't actually prove the
  grouping behavior. New data interleaves episode titles across shows
  and asserts on [show, episode] pairs.
- Drop dead `baseUrl` + `paths` from apps/ui/tsconfig.json (unused alias)
  to clear the TS 6 deprecation surfaced in the IDE.

* perf(collections): restore SQL fast path for deleteSoonest paging

Page-loading a collection with `deleteSoonest` was hydrating every row
in the collection before slicing — minutes-long blocking page loads on
collections of a few hundred items, especially on Jellyfin where
`getMetadata` isn't cached at the adapter layer.

`deleteSoonest` orders by `addDate + deleteAfterDays`, but
`deleteAfterDays` is constant per collection, so the only sort key that
matters lives on `collection_media.addDate`. SQL can paginate it
directly without touching MediaItem metadata.

`applyCollectionSort` (the media-server push) still applies the
day-bucketed title tiebreaker via the comparator, so the polished
alphabetical-within-day order is what users see when browsing the
actual Plex/Jellyfin collection. The Maintainerr UI page may show
same-day items in a slightly different order — acceptable because the
primary sort key is correct and Maintainerr's DB remains the source of
truth driving the next push.

Other explicit sorts (airDate / rating / watchCount / title) still go
through hydrate-then-paginate because their sort keys live on
MediaItem, not on collection_media.

---------

Co-authored-by: enoch85 <mailto@danielhansson.nu>
@maintainerr-automation

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@enoch85 enoch85 added this to the 3.11.0 milestone May 12, 2026
doonga pushed a commit to greyrock-labs/home-ops that referenced this pull request May 13, 2026
…11.1 ) (#29)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/maintainerr/maintainerr](https://github.com/Maintainerr/Maintainerr) | minor | `3.10.1` → `3.11.1` |

---

### Release Notes

<details>
<summary>Maintainerr/Maintainerr (ghcr.io/maintainerr/maintainerr)</summary>

### [`v3.11.1`](https://github.com/Maintainerr/Maintainerr/blob/HEAD/CHANGELOG.md#3111-2026-05-12)

[Compare Source](Maintainerr/Maintainerr@v3.11.0...v3.11.1)

#### Highlights

- Fixed an issue where Jellyfin libraries with "Group films into collections" enabled caused BoxSet members to incorrectly toggle in and out of rule results ([#&#8203;2870](Maintainerr/Maintainerr#2870)).
- Improved error message for invalid Plex library section IDs to better guide users in resolving configuration issues ([#&#8203;2883](Maintainerr/Maintainerr#2883)).
- Enhanced custom collection UX by renaming tags for clarity and adding tooltips to explain collection handling options ([#&#8203;2882](Maintainerr/Maintainerr#2882)).

#### Fixes

- Validated Jellyfin IDs before refresh to prevent errors ([#&#8203;2853](Maintainerr/Maintainerr#2853)).
- Improved error message when Plex library section ID is invalid ([#&#8203;2883](Maintainerr/Maintainerr#2883)).
- Resolved Jellyfin collection add/remove loop for BoxSet items ([#&#8203;2870](Maintainerr/Maintainerr#2870)).
- Clarified custom collection terminology and added warnings for disabling collection handling ([#&#8203;2882](Maintainerr/Maintainerr#2882)).
- Added explicit token permissions to the Fider move job to address CodeQL findings.
- Added environment gate to mitigate TOCTOU vulnerability in the release\_pr workflow ([#&#8203;2879](Maintainerr/Maintainerr#2879)).
- Addressed transitive dependency vulnerabilities by adding Yarn resolutions for specific packages ([#&#8203;2881](Maintainerr/Maintainerr#2881)).

#### Dependencies

- Updated 10 dependencies, including notable packages: vite, typeorm, and [@&#8203;typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/eslint-plugin).

#### New Contributors

- [@&#8203;blixten85](https://github.com/blixten85) made their first contribution in [#&#8203;2881](Maintainerr/Maintainerr#2881)

### [`v3.11.0`](https://github.com/Maintainerr/Maintainerr/blob/HEAD/CHANGELOG.md#3110-2026-05-11)

[Compare Source](Maintainerr/Maintainerr@v3.10.2...v3.11.0)

#### Highlights

- Added support for force-processing overlays and gated reset operations against concurrent processing runs ([#&#8203;2827](Maintainerr/Maintainerr#2827)).
- Improved collection sorting: collections now apply sort order on save and synchronize with the media server ([#&#8203;2860](Maintainerr/Maintainerr#2860)).
- Enhanced storage metrics: potential reclaimable storage is now split into movie, show, season, and episode panels ([#&#8203;2854](Maintainerr/Maintainerr#2854)).

#### Breaking Changes

- None.

#### Features

- Added force-processing support for overlay operations and gated reset operations against concurrent processing runs ([#&#8203;2827](Maintainerr/Maintainerr#2827)).
- Improved storage metrics by splitting potential reclaimable storage into movie, show, season, and episode panels ([#&#8203;2854](Maintainerr/Maintainerr#2854)).

#### Fixes

- Fixed collection sorting to apply on save and synchronize with the media server ([#&#8203;2860](Maintainerr/Maintainerr#2860)).
- Resolved issue where excluding a single episode incorrectly excluded all episodes of the same show ([#&#8203;2867](Maintainerr/Maintainerr#2867)).
- Fixed storage metrics to merge shared volumes across hosts when byte-exact ([#&#8203;2852](Maintainerr/Maintainerr#2852)).
- Fixed Jellyfin retry ID check to align with pre-filter logic ([#&#8203;2853](Maintainerr/Maintainerr#2853)).
- Addressed issue where reclaimed bytes were not credited when `sizeBytes` was not yet cached ([#&#8203;2855](Maintainerr/Maintainerr#2855)).

#### Performance

- None.

#### Database migrations

- Added a new `mediaServerSort` column to the `collection` table to support media server-specific sorting.

#### Internal

- Added typed TanStack Query test helpers and migrated UI spec mocks to use typed builders ([#&#8203;2863](Maintainerr/Maintainerr#2863)).
- Added an architecture overview document detailing the monorepo structure, runtime flow, and core components ([#&#8203;2817](Maintainerr/Maintainerr#2817)).

#### Dependencies

- Updated 5 dependencies, including notable updates to TypeScript and typescript-eslint.

### [`v3.10.2`](https://github.com/Maintainerr/Maintainerr/blob/HEAD/CHANGELOG.md#3102-2026-05-08)

[Compare Source](Maintainerr/Maintainerr@v3.10.1...v3.10.2)

#### Highlights

- Fixed incorrect version comparison logic that caused update notifications to fail for multi-digit version segments ([#&#8203;2838](Maintainerr/Maintainerr#2838)).
- Improved storage metrics by deduplicating reclaimable bytes and adding per-type cleanup byte counters ([#&#8203;2833](Maintainerr/Maintainerr#2833)).

</details>

---

### Configuration

📅 **Schedule**: (in timezone America/New_York)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNjAuNyIsInVwZGF0ZWRJblZlciI6IjQzLjE2MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL21pbm9yIl19-->

Reviewed-on: https://git.greyrock.io/greyrock-labs/home-ops/pulls/29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclusions prevent rule processing for entire TV show instead of specific episodes

1 participant