From b635b5a7e3b72c91922d36bce6b29265123f88f8 Mon Sep 17 00:00:00 2001 From: "Petrus.Z" Date: Thu, 18 Nov 2021 12:49:56 +0800 Subject: [PATCH] Paginate movies query Signed-off-by: Petrus.Z --- .../Validators/CollectionPostScanTask.cs | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/Emby.Server.Implementations/Library/Validators/CollectionPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/CollectionPostScanTask.cs index cd9e109ffe..123183c077 100644 --- a/Emby.Server.Implementations/Library/Validators/CollectionPostScanTask.cs +++ b/Emby.Server.Implementations/Library/Validators/CollectionPostScanTask.cs @@ -62,30 +62,40 @@ namespace Emby.Server.Implementations.Library.Validators continue; } - var movies = _libraryManager.GetItemList(new InternalItemsQuery - { - MediaTypes = new string[] { MediaType.Video }, - IncludeItemTypes = new[] { nameof(Movie) }, - IsVirtualItem = false, - OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }, - Parent = library, - Recursive = true - }); + var startIndex = 0; + var pagesize = 1000; - foreach (var m in movies) + while (true) { - if (m is Movie movie && !string.IsNullOrEmpty(movie.CollectionName)) + var movies = _libraryManager.GetItemList(new InternalItemsQuery { - if (collectionNameMoviesMap.TryGetValue(movie.CollectionName, out var movieList)) + MediaTypes = new string[] { MediaType.Video }, + IncludeItemTypes = new[] { nameof(Movie) }, + IsVirtualItem = false, + OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }, + Parent = library, + StartIndex = startIndex, + Limit = pagesize, + Recursive = true + }); + startIndex += pagesize; + + if (!movies.Any()) { + break; + } + + foreach (var m in movies) + { + if (m is Movie movie && !string.IsNullOrEmpty(movie.CollectionName)) { - if (!movieList.Contains(movie.Id)) + if (collectionNameMoviesMap.TryGetValue(movie.CollectionName, out var movieList)) { movieList.Add(movie.Id); } - } - else - { - collectionNameMoviesMap[movie.CollectionName] = new HashSet { movie.Id }; + else + { + collectionNameMoviesMap[movie.CollectionName] = new HashSet { movie.Id }; + } } } }