From ad6bde6355ab4a8cf9d4d6a51c62844bdc029fcb Mon Sep 17 00:00:00 2001 From: softworkz Date: Sat, 23 Apr 2016 06:30:05 +0200 Subject: [PATCH] Restrict metadata refresh of missing/virtual episodes This commit can significantly improe library scan times! (in my case from 15minutes to 50s) This fixes the following situation: When a user has a series in his library with lots of episodes (like thousands), the metadata for ALL series episodes was refreshed during each library scan. This resulted in very long scan times, even when using the provider's cached data. This fix skips metadata refresh for episodes that are NOT present in the local library and are having an airdate older than 30days (no more changes likely to occur) during library scans. But these skipped items would still be refreshed during a full metadata refresh. I believe this is an acceptable balance between performance and accuracy. --- MediaBrowser.Controller/Entities/TV/Series.cs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index 7eabff072d..ad4ee436e3 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -255,7 +255,7 @@ namespace MediaBrowser.Controller.Entities.TV // Refresh current item await RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false); - // Refresh TV + // Refresh seasons foreach (var item in seasons) { cancellationToken.ThrowIfCancellationRequested(); @@ -268,12 +268,30 @@ namespace MediaBrowser.Controller.Entities.TV progress.Report(percent * 100); } - // Refresh all non-songs + // Refresh episodes and other children foreach (var item in otherItems) { cancellationToken.ThrowIfCancellationRequested(); - await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false); + var skipItem = false; + + var episode = item as Episode; + + if (episode != null + && refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh + && !refreshOptions.ReplaceAllMetadata + && episode.IsMissingEpisode + && episode.LocationType == Model.Entities.LocationType.Virtual + && episode.PremiereDate.HasValue + && (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30) + { + skipItem = true; + } + + if (!skipItem) + { + await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false); + } numComplete++; double percent = numComplete;