Improve perf of db save and query

pull/5887/head
Bond_009 4 years ago
parent 95ab603a40
commit f46195899e

@ -89,7 +89,7 @@ namespace Jellyfin.Api.Controllers
// nameof(LiveTvProgram) // nameof(LiveTvProgram)
}, },
// IsMovie = true // IsMovie = true
OrderBy = new[] { ItemSortBy.DatePlayed, ItemSortBy.Random }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(), OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.Random, SortOrder.Descending) },
Limit = 7, Limit = 7,
ParentId = parentIdGuid, ParentId = parentIdGuid,
Recursive = true, Recursive = true,
@ -110,7 +110,7 @@ namespace Jellyfin.Api.Controllers
{ {
IncludeItemTypes = itemTypes.ToArray(), IncludeItemTypes = itemTypes.ToArray(),
IsMovie = true, IsMovie = true,
OrderBy = new[] { ItemSortBy.Random }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(), OrderBy = new[] { (ItemSortBy.Random, SortOrder.Descending) },
Limit = 10, Limit = 10,
IsFavoriteOrLiked = true, IsFavoriteOrLiked = true,
ExcludeItemIds = recentlyPlayedMovies.Select(i => i.Id).ToArray(), ExcludeItemIds = recentlyPlayedMovies.Select(i => i.Id).ToArray(),
@ -120,7 +120,7 @@ namespace Jellyfin.Api.Controllers
DtoOptions = dtoOptions DtoOptions = dtoOptions
}); });
var mostRecentMovies = recentlyPlayedMovies.Take(6).ToList(); var mostRecentMovies = recentlyPlayedMovies.GetRange(0, Math.Min(recentlyPlayedMovies.Count, 6));
// Get recently played directors // Get recently played directors
var recentDirectors = GetDirectors(mostRecentMovies) var recentDirectors = GetDirectors(mostRecentMovies)
.ToList(); .ToList();
@ -191,7 +191,8 @@ namespace Jellyfin.Api.Controllers
foreach (var name in names) foreach (var name in names)
{ {
var items = _libraryManager.GetItemList(new InternalItemsQuery(user) var items = _libraryManager.GetItemList(
new InternalItemsQuery(user)
{ {
Person = name, Person = name,
// Account for duplicates by imdb id, since the database doesn't support this yet // Account for duplicates by imdb id, since the database doesn't support this yet

@ -69,7 +69,7 @@ namespace Jellyfin.Api.Controllers
var dtoOptions = new DtoOptions().AddClientFields(Request); var dtoOptions = new DtoOptions().AddClientFields(Request);
var result = _libraryManager.GetItemsResult(new InternalItemsQuery(user) var result = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
{ {
OrderBy = new[] { ItemSortBy.Random }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(), OrderBy = new[] { (ItemSortBy.Random, SortOrder.Descending) },
MediaTypes = mediaType, MediaTypes = mediaType,
IncludeItemTypes = type, IncludeItemTypes = type,
IsVirtualItem = false, IsVirtualItem = false,

@ -155,7 +155,7 @@ namespace Jellyfin.Api.Controllers
var itemsResult = _libraryManager.GetItemList(new InternalItemsQuery(user) var itemsResult = _libraryManager.GetItemList(new InternalItemsQuery(user)
{ {
IncludeItemTypes = new[] { nameof(Episode) }, IncludeItemTypes = new[] { nameof(Episode) },
OrderBy = new[] { ItemSortBy.PremiereDate, ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), OrderBy = new[] { (ItemSortBy.PremiereDate, SortOrder.Ascending), (ItemSortBy.SortName, SortOrder.Ascending) },
MinPremiereDate = minPremiereDate, MinPremiereDate = minPremiereDate,
StartIndex = startIndex, StartIndex = startIndex,
Limit = limit, Limit = limit,

@ -99,7 +99,15 @@ namespace MediaBrowser.Controller.Entities.TV
take--; take--;
} }
list.InsertRange(0, seriesUserDataKeys.Take(take).Select(i => i + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000"))); var newList = seriesUserDataKeys.GetRange(0, take);
var suffix = ParentIndexNumber.Value.ToString("000", CultureInfo.InvariantCulture) + IndexNumber.Value.ToString("000", CultureInfo.InvariantCulture);
for (int i = 0; i < take; i++)
{
newList[i] = newList[i] + suffix;
}
newList.AddRange(list);
list = newList;
} }
return list; return list;

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Jellyfin.Data.Entities; using Jellyfin.Data.Entities;
@ -56,7 +57,15 @@ namespace MediaBrowser.Controller.Entities.TV
var series = Series; var series = Series;
if (series != null) if (series != null)
{ {
list.InsertRange(0, series.GetUserDataKeys().Select(i => i + (IndexNumber ?? 0).ToString("000"))); var newList = series.GetUserDataKeys();
var suffix = (IndexNumber ?? 0).ToString("000", CultureInfo.InvariantCulture);
for (int i = 0; i < newList.Count; i++)
{
newList[i] = newList[i] + suffix;
}
newList.AddRange(list);
list = newList;
} }
return list; return list;

@ -169,14 +169,12 @@ namespace MediaBrowser.Controller.Entities.TV
{ {
var list = base.GetUserDataKeys(); var list = base.GetUserDataKeys();
var key = this.GetProviderId(MetadataProvider.Imdb); if (this.TryGetProviderId(MetadataProvider.Imdb, out var key))
if (!string.IsNullOrEmpty(key))
{ {
list.Insert(0, key); list.Insert(0, key);
} }
key = this.GetProviderId(MetadataProvider.Tvdb); if (this.TryGetProviderId(MetadataProvider.Tvdb, out key))
if (!string.IsNullOrEmpty(key))
{ {
list.Insert(0, key); list.Insert(0, key);
} }
@ -208,7 +206,7 @@ namespace MediaBrowser.Controller.Entities.TV
query.AncestorWithPresentationUniqueKey = null; query.AncestorWithPresentationUniqueKey = null;
query.SeriesPresentationUniqueKey = seriesKey; query.SeriesPresentationUniqueKey = seriesKey;
query.IncludeItemTypes = new[] { nameof(Season) }; query.IncludeItemTypes = new[] { nameof(Season) };
query.OrderBy = new[] { ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(); query.OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) };
if (user != null && !user.DisplayMissingEpisodes) if (user != null && !user.DisplayMissingEpisodes)
{ {
@ -228,7 +226,7 @@ namespace MediaBrowser.Controller.Entities.TV
query.SeriesPresentationUniqueKey = seriesKey; query.SeriesPresentationUniqueKey = seriesKey;
if (query.OrderBy.Count == 0) if (query.OrderBy.Count == 0)
{ {
query.OrderBy = new[] { ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(); query.OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) };
} }
if (query.IncludeItemTypes.Length == 0) if (query.IncludeItemTypes.Length == 0)
@ -254,7 +252,7 @@ namespace MediaBrowser.Controller.Entities.TV
AncestorWithPresentationUniqueKey = null, AncestorWithPresentationUniqueKey = null,
SeriesPresentationUniqueKey = seriesKey, SeriesPresentationUniqueKey = seriesKey,
IncludeItemTypes = new[] { nameof(Episode), nameof(Season) }, IncludeItemTypes = new[] { nameof(Episode), nameof(Season) },
OrderBy = new[] { ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) },
DtoOptions = options DtoOptions = options
}; };
@ -365,7 +363,7 @@ namespace MediaBrowser.Controller.Entities.TV
AncestorWithPresentationUniqueKey = queryFromSeries ? null : seriesKey, AncestorWithPresentationUniqueKey = queryFromSeries ? null : seriesKey,
SeriesPresentationUniqueKey = queryFromSeries ? seriesKey : null, SeriesPresentationUniqueKey = queryFromSeries ? seriesKey : null,
IncludeItemTypes = new[] { nameof(Episode) }, IncludeItemTypes = new[] { nameof(Episode) },
OrderBy = new[] { ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) },
DtoOptions = options DtoOptions = options
}; };
if (user != null) if (user != null)

@ -217,8 +217,7 @@ namespace MediaBrowser.Controller.Entities
private QueryResult<BaseItem> GetMovieLatest(Folder parent, User user, InternalItemsQuery query) private QueryResult<BaseItem> GetMovieLatest(Folder parent, User user, InternalItemsQuery query)
{ {
query.OrderBy = new[] { ItemSortBy.DateCreated, ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(); query.OrderBy = new[] { (ItemSortBy.DateCreated, SortOrder.Descending), (ItemSortBy.SortName, SortOrder.Descending) };
query.Recursive = true; query.Recursive = true;
query.Parent = parent; query.Parent = parent;
query.SetUser(user); query.SetUser(user);
@ -230,7 +229,7 @@ namespace MediaBrowser.Controller.Entities
private QueryResult<BaseItem> GetMovieResume(Folder parent, User user, InternalItemsQuery query) private QueryResult<BaseItem> GetMovieResume(Folder parent, User user, InternalItemsQuery query)
{ {
query.OrderBy = new[] { ItemSortBy.DatePlayed, ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(); query.OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.SortName, SortOrder.Descending) };
query.IsResumable = true; query.IsResumable = true;
query.Recursive = true; query.Recursive = true;
query.Parent = parent; query.Parent = parent;
@ -327,8 +326,7 @@ namespace MediaBrowser.Controller.Entities
private QueryResult<BaseItem> GetTvLatest(Folder parent, User user, InternalItemsQuery query) private QueryResult<BaseItem> GetTvLatest(Folder parent, User user, InternalItemsQuery query)
{ {
query.OrderBy = new[] { ItemSortBy.DateCreated, ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(); query.OrderBy = new[] { (ItemSortBy.DateCreated, SortOrder.Descending), (ItemSortBy.SortName, SortOrder.Descending) };
query.Recursive = true; query.Recursive = true;
query.Parent = parent; query.Parent = parent;
query.SetUser(user); query.SetUser(user);
@ -356,7 +354,7 @@ namespace MediaBrowser.Controller.Entities
private QueryResult<BaseItem> GetTvResume(Folder parent, User user, InternalItemsQuery query) private QueryResult<BaseItem> GetTvResume(Folder parent, User user, InternalItemsQuery query)
{ {
query.OrderBy = new[] { ItemSortBy.DatePlayed, ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(); query.OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.SortName, SortOrder.Descending) };
query.IsResumable = true; query.IsResumable = true;
query.Recursive = true; query.Recursive = true;
query.Parent = parent; query.Parent = parent;

@ -163,7 +163,7 @@ namespace MediaBrowser.Controller.Playlists
Recursive = true, Recursive = true,
IncludeItemTypes = new[] { nameof(Audio) }, IncludeItemTypes = new[] { nameof(Audio) },
GenreIds = new[] { musicGenre.Id }, GenreIds = new[] { musicGenre.Id },
OrderBy = new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), OrderBy = new[] { (ItemSortBy.AlbumArtist, SortOrder.Ascending), (ItemSortBy.Album, SortOrder.Ascending), (ItemSortBy.SortName, SortOrder.Ascending) },
DtoOptions = options DtoOptions = options
}); });
} }
@ -175,7 +175,7 @@ namespace MediaBrowser.Controller.Playlists
Recursive = true, Recursive = true,
IncludeItemTypes = new[] { nameof(Audio) }, IncludeItemTypes = new[] { nameof(Audio) },
ArtistIds = new[] { musicArtist.Id }, ArtistIds = new[] { musicArtist.Id },
OrderBy = new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(), OrderBy = new[] { (ItemSortBy.AlbumArtist, SortOrder.Ascending), (ItemSortBy.Album, SortOrder.Ascending), (ItemSortBy.SortName, SortOrder.Ascending) },
DtoOptions = options DtoOptions = options
}); });
} }

Loading…
Cancel
Save