Files
ersatztv/ErsatzTV.Core/Interfaces/Repositories/IMediaServerTelevisionRepository.cs
T
timothyandClaude Opus 4.8 61bd374494
Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 7s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 24s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 7s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 5m52s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 5m36s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 8s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 9s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 19m14s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
fix(476): cascade FileNotFound from removed shows/seasons to descendants
The media-server television scanner reconciles removed items at three levels
via existing.Except(incoming), but the season and episode sweeps live inside
the per-parent loops (ScanSeasons inside the show loop, ScanEpisodes inside the
season loop). Those loops only iterate parents present in the incoming list, so
a show (or season) that is gone from the media server is never visited and its
descendants are never swept — they keep their last state. On Jellyfin/Emby that
is RemoteOnly, which PlayoutBuilder does NOT skip even with PlayoutSkipMissingItems
on, so every orphaned episode keeps getting scheduled as a guaranteed tune-in
failure (the #473 reproduction; 717 stale prod rows across 10 removed shows).

Fix: cascade the flag by parent MediaItem.Id. Two provider-agnostic repo helpers
(Season.ShowId / Episode.SeasonId are on the base tables) flag descendants and the
scanner drives them after each parent sweep — show → seasons → episodes, and
season → episodes for the show-present case. Shared abstract base fixes
Jellyfin/Plex/Emby at once; Movie/OtherVideo are flat and have no such gap.

Tests: a Scanner.Tests case asserts the scanner cascades through the (substituted)
repository (non-vacuous — fails if the cascade calls are removed), and Integration
tests exercise the real cascade SQL against the schema, proving it flags only the
targeted subtree and no-ops on empty input.

fixes #476

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 21:49:33 +02:00

63 lines
2.9 KiB
C#

using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Metadata;
namespace ErsatzTV.Core.Interfaces.Repositories;
public interface IMediaServerTelevisionRepository<in TLibrary, TShow, TSeason, TEpisode, TEtag> where TLibrary : Library
where TShow : Show
where TSeason : Season
where TEpisode : Episode
where TEtag : MediaServerItemEtag
{
Task<List<TEtag>> GetExistingShows(TLibrary library, CancellationToken cancellationToken);
Task<List<TEtag>> GetExistingSeasons(TLibrary library, TShow show, CancellationToken cancellationToken);
Task<List<TEtag>> GetExistingEpisodes(TLibrary library, TSeason season, CancellationToken cancellationToken);
Task<Either<BaseError, MediaItemScanResult<TShow>>> GetOrAdd(
TLibrary library,
TShow item,
CancellationToken cancellationToken);
Task<Either<BaseError, MediaItemScanResult<TSeason>>> GetOrAdd(
TLibrary library,
TSeason item,
CancellationToken cancellationToken);
Task<Either<BaseError, MediaItemScanResult<TEpisode>>> GetOrAdd(
TLibrary library,
TEpisode item,
bool deepScan,
CancellationToken cancellationToken);
Task<Unit> SetEtag(TShow show, string etag, CancellationToken cancellationToken);
Task<Unit> SetEtag(TSeason season, string etag, CancellationToken cancellationToken);
Task<Unit> SetEtag(TEpisode episode, string etag, CancellationToken cancellationToken);
Task<Option<int>> FlagNormal(TLibrary library, TEpisode episode, CancellationToken cancellationToken);
Task<Option<int>> FlagNormal(TLibrary library, TSeason season, CancellationToken cancellationToken);
Task<Option<int>> FlagNormal(TLibrary library, TShow show, CancellationToken cancellationToken);
Task<List<int>> FlagFileNotFoundShows(
TLibrary library,
List<string> showItemIds,
CancellationToken cancellationToken);
Task<List<int>> FlagFileNotFoundSeasons(
TLibrary library,
List<string> seasonItemIds,
CancellationToken cancellationToken);
Task<List<int>> FlagFileNotFoundEpisodes(
TLibrary library,
List<string> episodeItemIds,
CancellationToken cancellationToken);
// Cascade helpers (#476): when a parent is swept to FileNotFound because it is gone from the media
// server, the per-parent loop never visits it, so its descendants are never reconciled. These flag
// the descendants by parent MediaItem.Id (Season.ShowId / Episode.SeasonId are on the base tables).
Task<List<int>> FlagFileNotFoundSeasonsForShows(
List<int> showIds,
CancellationToken cancellationToken);
Task<List<int>> FlagFileNotFoundEpisodesForSeasons(
List<int> seasonIds,
CancellationToken cancellationToken);
Task<Option<int>> FlagUnavailable(TLibrary library, TEpisode episode, CancellationToken cancellationToken);
Task<Option<int>> FlagRemoteOnly(TLibrary library, TEpisode episode, CancellationToken cancellationToken);
}