浏览代码

Paginate movies query

Signed-off-by: Petrus.Z <silencly07@gmail.com>
Petrus.Z 3 年之前
父节点
当前提交
b635b5a7e3
共有 1 个文件被更改,包括 27 次插入17 次删除
  1. 27 17
      Emby.Server.Implementations/Library/Validators/CollectionPostScanTask.cs

+ 27 - 17
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
+                    {
+                        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 (collectionNameMoviesMap.TryGetValue(movie.CollectionName, out var movieList))
+                        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<Guid> { movie.Id };
+                            else
+                            {
+                                collectionNameMoviesMap[movie.CollectionName] = new HashSet<Guid> { movie.Id };
+                            }
                         }
                     }
                 }