#nullable disable #pragma warning disable CS1591 using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Jellyfin.Data.Enums; using Jellyfin.Database.Implementations.Entities; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; using LinkedChildType = MediaBrowser.Controller.Entities.LinkedChildType; namespace MediaBrowser.Controller.Persistence; /// /// Provides an interface to implement an Item repository. /// public interface IItemRepository { /// /// Deletes the item. /// /// The identifier to delete. void DeleteItem(params IReadOnlyList ids); /// /// Saves the items. /// /// The items. /// The cancellation token. void SaveItems(IReadOnlyList items, CancellationToken cancellationToken); Task SaveImagesAsync(BaseItem item, CancellationToken cancellationToken = default); /// /// Reattaches the user data to the item. /// /// The item. /// The cancellation token. /// A task that represents the asynchronous reattachment operation. Task ReattachUserDataAsync(BaseItem item, CancellationToken cancellationToken); /// /// Retrieves the item. /// /// The id. /// BaseItem. BaseItem RetrieveItem(Guid id); /// /// Gets the items. /// /// The query. /// QueryResult<BaseItem>. QueryResult GetItems(InternalItemsQuery filter); /// /// Gets the item ids list. /// /// The query. /// List<Guid>. IReadOnlyList GetItemIdsList(InternalItemsQuery filter); /// /// Gets the item list. /// /// The query. /// List<BaseItem>. IReadOnlyList GetItemList(InternalItemsQuery filter); /// /// Gets the item list. Used mainly by the Latest api endpoint. /// /// The query. /// Collection Type. /// List<BaseItem>. IReadOnlyList GetLatestItemList(InternalItemsQuery filter, CollectionType collectionType); /// /// Gets the list of series presentation keys for next up. /// /// The query. /// The minimum date for a series to have been most recently watched. /// The list of keys. IReadOnlyList GetNextUpSeriesKeys(InternalItemsQuery filter, DateTime dateCutoff); /// /// Gets next up episodes for multiple series in a single batched query. /// Returns the last watched episode, next unwatched episode, specials, and next played episode for each series. /// /// The query filter. /// The series presentation unique keys to query. /// Whether to include specials (ParentIndexNumber = 0) in the results. /// Whether to include watched episodes for rewatching mode. /// A dictionary mapping series key to batch result containing episodes needed for NextUp calculation. IReadOnlyDictionary GetNextUpEpisodesBatch( InternalItemsQuery filter, IReadOnlyList seriesKeys, bool includeSpecials, bool includeWatchedForRewatching); /// /// Updates the inherited values. /// void UpdateInheritedValues(); int GetCount(InternalItemsQuery filter); ItemCounts GetItemCounts(InternalItemsQuery filter); QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetGenres(InternalItemsQuery filter); QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetMusicGenres(InternalItemsQuery filter); QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetStudios(InternalItemsQuery filter); QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetArtists(InternalItemsQuery filter); QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetAlbumArtists(InternalItemsQuery filter); QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetAllArtists(InternalItemsQuery filter); IReadOnlyList GetMusicGenreNames(); IReadOnlyList GetStudioNames(); IReadOnlyList GetGenreNames(); IReadOnlyList GetAllArtistNames(); /// /// Checks if an item has been persisted to the database. /// /// The id to check. /// True if the item exists, otherwise false. Task ItemExistsAsync(Guid id); /// /// Gets a value indicating wherever all children of the requested Id has been played. /// /// The userdata to check against. /// The Top id to check. /// Whever the check should be done recursive. Warning expensive operation. /// A value indicating whever all children has been played. bool GetIsPlayed(User user, Guid id, bool recursive); /// /// Gets the count of played items that are descendants of the specified ancestor. /// Uses the AncestorIds table for efficient recursive lookup. /// Applies user access filtering (library access, parental controls, tags). /// /// The query filter containing user access settings. /// The ancestor item id. /// The count of played descendant items. int GetPlayedCount(InternalItemsQuery filter, Guid ancestorId); /// /// Gets the total count of items that are descendants of the specified ancestor. /// Uses the AncestorIds table for efficient recursive lookup. /// Applies user access filtering (library access, parental controls, tags). /// /// The query filter containing user access settings. /// The ancestor item id. /// The total count of descendant items. int GetTotalCount(InternalItemsQuery filter, Guid ancestorId); /// /// Gets both the played count and total count of items that are descendants of the specified ancestor. /// Uses the AncestorIds table for efficient recursive lookup. /// Applies user access filtering (library access, parental controls, tags). /// /// The query filter containing user access settings. /// The ancestor item id. /// A tuple containing (Played count, Total count). (int Played, int Total) GetPlayedAndTotalCount(InternalItemsQuery filter, Guid ancestorId); /// /// Gets both the played count and total count of items that are linked children of the specified parent. /// Uses the LinkedChildren table for BoxSets, Playlists, etc. /// Applies user access filtering (library access, parental controls, tags). /// /// The query filter containing user access settings. /// The parent item id (BoxSet, Playlist, etc.). /// A tuple containing (Played count, Total count). (int Played, int Total) GetPlayedAndTotalCountFromLinkedChildren(InternalItemsQuery filter, Guid parentId); /// /// Batch-fetches played and total counts for multiple folder items using the AncestorIds table. /// This avoids N+1 queries when building DTOs for lists of folder items (Series, Seasons, etc.). /// Applies user access filtering (parental controls, tags). /// /// The list of folder item IDs to get counts for. /// The user for access filtering and played status. /// Dictionary mapping folder ID to (Played count, Total count). Dictionary GetPlayedAndTotalCountBatch(IReadOnlyList folderIds, User user); /// /// Gets the IDs of linked children for the specified parent. /// /// The parent item ID. /// Optional child type filter (e.g., LocalAlternateVersion, LinkedAlternateVersion). /// List of child item IDs. IReadOnlyList GetLinkedChildrenIds(Guid parentId, int? childType = null); /// /// Gets all artist matches from the db. /// /// The names of the artists. /// A map of the artist name and the potential matches. IReadOnlyDictionary FindArtists(IReadOnlyList artistNames); /// /// Batch-fetches child counts for multiple parent folders. /// Returns the count of immediate children (non-recursive) for each parent. /// /// The list of parent folder IDs. /// The user ID for access filtering. /// Dictionary mapping parent ID to child count. Dictionary GetChildCountBatch(IReadOnlyList parentIds, Guid? userId); /// /// Gets parent IDs (Playlists/BoxSets) that reference the specified child with LinkedChildType.Manual. /// /// The child item ID. /// List of parent IDs that reference the child. IReadOnlyList GetManualLinkedParentIds(Guid childId); /// /// Gets legacy query filters (Years, Genres, Tags, OfficialRatings) aggregated directly from the database. /// /// The query filter. /// Aggregated filter values. QueryFiltersLegacy GetQueryFiltersLegacy(InternalItemsQuery filter); /// /// Updates LinkedChildren references from one child to another, preserving SortOrder. /// Handles duplicates: if parent already references toChildId, removes the old reference instead. /// Used when video versions change to maintain collection integrity. /// /// The child ID to re-route from. /// The child ID to re-route to. /// Number of references updated. int RerouteLinkedChildren(Guid fromChildId, Guid toChildId); /// /// Creates or updates a LinkedChild entry linking a parent to a child item. /// If the link already exists, updates the child type. /// /// The parent item ID. /// The child item ID. /// The type of linked child relationship. void UpsertLinkedChild(Guid parentId, Guid childId, LinkedChildType childType); }