From 2bac4f85ad1dfe23710554ceee5ffea093092157 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 21 Mar 2017 13:31:40 -0400 Subject: [PATCH 1/2] improve next up performance --- .../TV/TVSeriesManager.cs | 31 +++++++++++-------- MediaBrowser.Api/TvShowsService.cs | 9 +++++- MediaBrowser.Model/Querying/NextUpQuery.cs | 3 ++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.cs index 9dfaa102a..b5e64bc23 100644 --- a/Emby.Server.Implementations/TV/TVSeriesManager.cs +++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs @@ -77,7 +77,7 @@ namespace Emby.Server.Implementations.TV // Avoid implicitly captured closure var episodes = GetNextUpEpisodes(request, user, items); - return GetResult(episodes, null, request); + return GetResult(episodes, request); } public QueryResult GetNextUp(NextUpQuery request, List parentsFolders) @@ -128,7 +128,7 @@ namespace Emby.Server.Implementations.TV // Avoid implicitly captured closure var episodes = GetNextUpEpisodes(request, user, items); - return GetResult(episodes, null, request); + return GetResult(episodes, request); } public IEnumerable GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable seriesKeys) @@ -163,8 +163,7 @@ namespace Emby.Server.Implementations.TV return false; }) .Select(i => i.Item2()) - .Where(i => i != null) - .Take(request.Limit ?? int.MaxValue); + .Where(i => i != null); } private string GetUniqueSeriesKey(BaseItem series) @@ -232,24 +231,30 @@ namespace Emby.Server.Implementations.TV return new Tuple>(DateTime.MinValue, getEpisode); } - private QueryResult GetResult(IEnumerable items, int? totalRecordLimit, NextUpQuery query) + private QueryResult GetResult(IEnumerable items, NextUpQuery query) { - var itemsArray = totalRecordLimit.HasValue ? items.Take(totalRecordLimit.Value).ToArray() : items.ToArray(); - var totalCount = itemsArray.Length; + int totalCount = 0; + if (query.EnableTotalRecordCount) + { + var list = items.ToList(); + totalCount = list.Count; + items = list; + } + + if (query.StartIndex.HasValue) + { + items = items.Skip(query.StartIndex.Value); + } if (query.Limit.HasValue) { - itemsArray = itemsArray.Skip(query.StartIndex ?? 0).Take(query.Limit.Value).ToArray(); - } - else if (query.StartIndex.HasValue) - { - itemsArray = itemsArray.Skip(query.StartIndex.Value).ToArray(); + items = items.Take(query.Limit.Value); } return new QueryResult { TotalRecordCount = totalCount, - Items = itemsArray + Items = items.ToArray() }; } } diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index 71c5e732a..43fe74d5f 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -72,6 +72,12 @@ namespace MediaBrowser.Api [ApiMember(Name = "EnableUserData", Description = "Optional, include user data", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] public bool? EnableUserData { get; set; } + public bool EnableTotalRecordCount { get; set; } + + public GetNextUpEpisodes() + { + EnableTotalRecordCount = true; + } } [Route("/Shows/Upcoming", "GET", Summary = "Gets a list of upcoming episodes")] @@ -376,7 +382,8 @@ namespace MediaBrowser.Api ParentId = request.ParentId, SeriesId = request.SeriesId, StartIndex = request.StartIndex, - UserId = request.UserId + UserId = request.UserId, + EnableTotalRecordCount = request.EnableTotalRecordCount }); var user = _userManager.GetUserById(request.UserId); diff --git a/MediaBrowser.Model/Querying/NextUpQuery.cs b/MediaBrowser.Model/Querying/NextUpQuery.cs index b5f50bde0..e3b0d578a 100644 --- a/MediaBrowser.Model/Querying/NextUpQuery.cs +++ b/MediaBrowser.Model/Querying/NextUpQuery.cs @@ -55,9 +55,12 @@ namespace MediaBrowser.Model.Querying /// The enable image types. public ImageType[] EnableImageTypes { get; set; } + public bool EnableTotalRecordCount { get; set; } + public NextUpQuery() { EnableImageTypes = new ImageType[] {}; + EnableTotalRecordCount = true; } } } From d5b861c88e1b81097c75122d10e848dd9cf50e53 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 21 Mar 2017 13:31:56 -0400 Subject: [PATCH 2/2] 3.2.8.7 --- SharedVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SharedVersion.cs b/SharedVersion.cs index 6582f8f0f..34981db41 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.8.6")] +[assembly: AssemblyVersion("3.2.8.7")]