From 5996c4afce11249804d24f1caa3a99b390543c4d Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Sat, 17 Jan 2026 17:10:07 +0100 Subject: Complete LinkedChildren integration and batch DTO optimizations This commit integrates remaining performance changes: - Add batch user data fetching in DtoService to reduce N+1 queries - Add GetNextUpEpisodesBatch in TVSeriesManager for efficient batch retrieval - Update Video/Movie/BoxSet to use LibraryManager for alternate versions - Transition LinkedChild to use ItemId instead of Path (obsolete Path/LibraryItemId) - Update providers and controllers for LinkedChildren-based references - Add NextUpEpisodeBatchResult for batched episode queries - Integrate IDescendantQueryProvider in SqliteDatabaseProvider --- .../Parsers/BaseItemXmlParser.cs | 5 +++- MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs | 31 +++++++++++----------- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'MediaBrowser.LocalMetadata') diff --git a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs index 119effe791..cf1423d02d 100644 --- a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs @@ -780,7 +780,8 @@ namespace MediaBrowser.LocalMetadata.Parsers } /// - /// Get linked child. + /// Get linked child from XML. Uses deprecated Path/LibraryItemId properties for backward compatibility + /// with existing XML files. These will be resolved to ItemId when the linked child is accessed. /// /// The xml reader. /// The linked child. @@ -791,6 +792,7 @@ namespace MediaBrowser.LocalMetadata.Parsers reader.MoveToContent(); reader.Read(); +#pragma warning disable CS0618 // Type or member is obsolete - reading legacy XML format for backward compatibility // Loop through each element while (!reader.EOF && reader.ReadState == ReadState.Interactive) { @@ -820,6 +822,7 @@ namespace MediaBrowser.LocalMetadata.Parsers { return linkedItem; } +#pragma warning restore CS0618 return null; } diff --git a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs index 025a815247..a065b68321 100644 --- a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs @@ -467,41 +467,40 @@ namespace MediaBrowser.LocalMetadata.Savers } /// - /// ADd linked children. + /// Add linked children. /// /// The item. /// The xml writer. /// The plural node name. /// The singular node name. /// The task object representing the asynchronous operation. - private static async Task AddLinkedChildren(Folder item, XmlWriter writer, string pluralNodeName, string singularNodeName) + private async Task AddLinkedChildren(Folder item, XmlWriter writer, string pluralNodeName, string singularNodeName) { - var items = item.LinkedChildren + var linkedChildren = item.LinkedChildren .Where(i => i.Type == LinkedChildType.Manual) .ToList(); - if (items.Count == 0) + if (linkedChildren.Count == 0) { return; } await writer.WriteStartElementAsync(null, pluralNodeName, null).ConfigureAwait(false); - foreach (var link in items) + foreach (var link in linkedChildren) { - if (!string.IsNullOrWhiteSpace(link.Path) || !string.IsNullOrWhiteSpace(link.LibraryItemId)) + // Resolve ItemId to get the item's path for XML portability + string? path = null; + if (link.ItemId.HasValue && !link.ItemId.Value.Equals(Guid.Empty)) { - await writer.WriteStartElementAsync(null, singularNodeName, null).ConfigureAwait(false); - if (!string.IsNullOrWhiteSpace(link.Path)) - { - await writer.WriteElementStringAsync(null, "Path", null, link.Path).ConfigureAwait(false); - } - - if (!string.IsNullOrWhiteSpace(link.LibraryItemId)) - { - await writer.WriteElementStringAsync(null, "ItemId", null, link.LibraryItemId).ConfigureAwait(false); - } + var linkedItem = LibraryManager.GetItemById(link.ItemId.Value); + path = linkedItem?.Path; + } + if (!string.IsNullOrWhiteSpace(path)) + { + await writer.WriteStartElementAsync(null, singularNodeName, null).ConfigureAwait(false); + await writer.WriteElementStringAsync(null, "Path", null, path).ConfigureAwait(false); await writer.WriteEndElementAsync().ConfigureAwait(false); } } -- cgit v1.2.3