mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-19 08:36:37 +00:00
Fix warnings, improve performance (#1665)
* Fix warnings, improve performance `QueryResult.Items` is now a `IReadOnlyList` so we don't need to allocate a new `Array` when we have a `List` (and `Items` shouldn't need to be mutable anyway) * Update Providers .csproj to latest C# * Remove extra newline from DtoService.cs * Remove extra newline from UserLibraryService.cs
This commit is contained in:
@@ -57,7 +57,7 @@ namespace MediaBrowser.Controller.Dto
|
||||
/// <param name="options">The options.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="owner">The owner.</param>
|
||||
BaseItemDto[] GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null);
|
||||
IReadOnlyList<BaseItemDto> GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the item by name dto.
|
||||
|
||||
@@ -2871,16 +2871,16 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// Gets or sets the remote trailers.
|
||||
/// </summary>
|
||||
/// <value>The remote trailers.</value>
|
||||
public MediaUrl[] RemoteTrailers { get; set; }
|
||||
public IReadOnlyList<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
public IEnumerable<BaseItem> GetExtras()
|
||||
{
|
||||
return ExtraIds.Select(LibraryManager.GetItemById).Where(i => i != null).OrderBy(i => i.SortName);
|
||||
}
|
||||
|
||||
public IEnumerable<BaseItem> GetExtras(ExtraType[] extraTypes)
|
||||
public IEnumerable<BaseItem> GetExtras(IReadOnlyCollection<ExtraType> extraTypes)
|
||||
{
|
||||
return ExtraIds.Select(LibraryManager.GetItemById).Where(i => i != null && extraTypes.Contains(i.ExtraType.Value)).OrderBy(i => i.SortName);
|
||||
return ExtraIds.Select(LibraryManager.GetItemById).Where(i => i != null && extraTypes.Contains(i.ExtraType.Value));
|
||||
}
|
||||
|
||||
public IEnumerable<BaseItem> GetTrailers()
|
||||
@@ -2908,7 +2908,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
|
||||
// Possible types of extra videos
|
||||
public static ExtraType[] DisplayExtraTypes = new[] { Model.Entities.ExtraType.BehindTheScenes, Model.Entities.ExtraType.Clip, Model.Entities.ExtraType.DeletedScene, Model.Entities.ExtraType.Interview, Model.Entities.ExtraType.Sample, Model.Entities.ExtraType.Scene };
|
||||
public static readonly IReadOnlyCollection<ExtraType> DisplayExtraTypes = new[] { Model.Entities.ExtraType.BehindTheScenes, Model.Entities.ExtraType.Clip, Model.Entities.ExtraType.DeletedScene, Model.Entities.ExtraType.Interview, Model.Entities.ExtraType.Sample, Model.Entities.ExtraType.Scene };
|
||||
|
||||
public virtual bool SupportsExternalTransfer => false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
@@ -28,13 +29,17 @@ namespace MediaBrowser.Controller.Entities
|
||||
Url = url
|
||||
};
|
||||
|
||||
if (item.RemoteTrailers.Length == 0)
|
||||
if (item.RemoteTrailers.Count == 0)
|
||||
{
|
||||
item.RemoteTrailers = new[] { mediaUrl };
|
||||
}
|
||||
else
|
||||
{
|
||||
item.RemoteTrailers = item.RemoteTrailers.Concat(new[] { mediaUrl }).ToArray();
|
||||
var oldIds = item.RemoteTrailers;
|
||||
var newIds = new MediaUrl[oldIds.Count + 1];
|
||||
oldIds.CopyTo(newIds);
|
||||
newIds[oldIds.Count] = mediaUrl;
|
||||
item.RemoteTrailers = newIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,36 +666,36 @@ namespace MediaBrowser.Controller.Entities
|
||||
query.StartIndex = null;
|
||||
query.Limit = null;
|
||||
|
||||
var itemsList = LibraryManager.GetItemList(query);
|
||||
IEnumerable<BaseItem> itemsList = LibraryManager.GetItemList(query);
|
||||
var user = query.User;
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
// needed for boxsets
|
||||
itemsList = itemsList.Where(i => i.IsVisibleStandalone(query.User)).ToList();
|
||||
itemsList = itemsList.Where(i => i.IsVisibleStandalone(query.User));
|
||||
}
|
||||
|
||||
BaseItem[] returnItems;
|
||||
IEnumerable<BaseItem> returnItems;
|
||||
int totalCount = 0;
|
||||
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
var itemsArray = itemsList.ToArray();
|
||||
totalCount = itemsArray.Length;
|
||||
returnItems = itemsArray;
|
||||
var itemArray = itemsList.ToArray();
|
||||
totalCount = itemArray.Length;
|
||||
returnItems = itemArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnItems = itemsList.ToArray();
|
||||
returnItems = itemsList;
|
||||
}
|
||||
|
||||
if (limit.HasValue)
|
||||
{
|
||||
returnItems = returnItems.Skip(startIndex ?? 0).Take(limit.Value).ToArray();
|
||||
returnItems = returnItems.Skip(startIndex ?? 0).Take(limit.Value);
|
||||
}
|
||||
else if (startIndex.HasValue)
|
||||
{
|
||||
returnItems = returnItems.Skip(startIndex.Value).ToArray();
|
||||
returnItems = returnItems.Skip(startIndex.Value);
|
||||
}
|
||||
|
||||
return new QueryResult<BaseItem>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
@@ -11,29 +10,82 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// Gets or sets the remote trailers.
|
||||
/// </summary>
|
||||
/// <value>The remote trailers.</value>
|
||||
MediaUrl[] RemoteTrailers { get; set; }
|
||||
IReadOnlyList<MediaUrl> RemoteTrailers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the local trailer ids.
|
||||
/// </summary>
|
||||
/// <value>The local trailer ids.</value>
|
||||
Guid[] LocalTrailerIds { get; set; }
|
||||
Guid[] RemoteTrailerIds { get; set; }
|
||||
IReadOnlyList<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the remote trailer ids.
|
||||
/// </summary>
|
||||
/// <value>The remote trailer ids.</value>
|
||||
IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
|
||||
|
||||
Guid Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class providing extension methods for working with <see cref="IHasTrailers" />.
|
||||
/// </summary>
|
||||
public static class HasTrailerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the trailer count.
|
||||
/// </summary>
|
||||
/// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
|
||||
public static int GetTrailerCount(this IHasTrailers item)
|
||||
=> item.LocalTrailerIds.Count + item.RemoteTrailerIds.Count;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trailer ids.
|
||||
/// </summary>
|
||||
/// <returns>List<Guid>.</returns>
|
||||
public static List<Guid> GetTrailerIds(this IHasTrailers item)
|
||||
/// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
|
||||
public static IReadOnlyList<Guid> GetTrailerIds(this IHasTrailers item)
|
||||
{
|
||||
var list = item.LocalTrailerIds.ToList();
|
||||
list.AddRange(item.RemoteTrailerIds);
|
||||
return list;
|
||||
var localIds = item.LocalTrailerIds;
|
||||
var remoteIds = item.RemoteTrailerIds;
|
||||
|
||||
var all = new Guid[localIds.Count + remoteIds.Count];
|
||||
var index = 0;
|
||||
foreach (var id in localIds)
|
||||
{
|
||||
all[index++] = id;
|
||||
}
|
||||
|
||||
foreach (var id in remoteIds)
|
||||
{
|
||||
all[index++] = id;
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trailers.
|
||||
/// </summary>
|
||||
/// <returns><see cref="IReadOnlyList{BaseItem}" />.</returns>
|
||||
public static IReadOnlyList<BaseItem> GetTrailers(this IHasTrailers item)
|
||||
{
|
||||
var localIds = item.LocalTrailerIds;
|
||||
var remoteIds = item.RemoteTrailerIds;
|
||||
var libraryManager = BaseItem.LibraryManager;
|
||||
|
||||
var all = new BaseItem[localIds.Count + remoteIds.Count];
|
||||
var index = 0;
|
||||
foreach (var id in localIds)
|
||||
{
|
||||
all[index++] = libraryManager.GetItemById(id);
|
||||
}
|
||||
|
||||
foreach (var id in remoteIds)
|
||||
{
|
||||
all[index++] = libraryManager.GetItemById(id);
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,11 @@ namespace MediaBrowser.Controller.Entities.Movies
|
||||
[IgnoreDataMember]
|
||||
public override bool SupportsPeople => true;
|
||||
|
||||
public Guid[] LocalTrailerIds { get; set; }
|
||||
public Guid[] RemoteTrailerIds { get; set; }
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the display order.
|
||||
@@ -61,7 +64,8 @@ namespace MediaBrowser.Controller.Entities.Movies
|
||||
{
|
||||
return base.GetNonCachedChildren(directoryService);
|
||||
}
|
||||
return new List<BaseItem>();
|
||||
|
||||
return Enumerable.Empty<BaseItem>();
|
||||
}
|
||||
|
||||
protected override List<BaseItem> LoadChildren()
|
||||
|
||||
@@ -27,8 +27,11 @@ namespace MediaBrowser.Controller.Entities.Movies
|
||||
RemoteTrailerIds = Array.Empty<Guid>();
|
||||
}
|
||||
|
||||
public Guid[] LocalTrailerIds { get; set; }
|
||||
public Guid[] RemoteTrailerIds { get; set; }
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the TMDB collection.
|
||||
|
||||
@@ -23,8 +23,11 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
RemoteTrailerIds = Array.Empty<Guid>();
|
||||
}
|
||||
|
||||
public Guid[] LocalTrailerIds { get; set; }
|
||||
public Guid[] RemoteTrailerIds { get; set; }
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the season in which it aired.
|
||||
|
||||
@@ -46,8 +46,11 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
[IgnoreDataMember]
|
||||
public override bool SupportsPeople => true;
|
||||
|
||||
public Guid[] LocalTrailerIds { get; set; }
|
||||
public Guid[] RemoteTrailerIds { get; set; }
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> LocalTrailerIds { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// airdate, dvd or absolute
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace MediaBrowser.Controller.LiveTv
|
||||
/// <param name="fields">The fields.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task AddInfoToProgramDto(List<Tuple<BaseItem, BaseItemDto>> programs, ItemFields[] fields, User user = null);
|
||||
Task AddInfoToProgramDto(IReadOnlyCollection<(BaseItem, BaseItemDto)> programs, ItemFields[] fields, User user = null);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the tuner host.
|
||||
@@ -258,7 +258,7 @@ namespace MediaBrowser.Controller.LiveTv
|
||||
/// <param name="items">The items.</param>
|
||||
/// <param name="options">The options.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
void AddChannelInfo(List<Tuple<BaseItemDto, LiveTvChannel>> items, DtoOptions options, User user);
|
||||
void AddChannelInfo(IReadOnlyCollection<(BaseItemDto, LiveTvChannel)> items, DtoOptions options, User user);
|
||||
|
||||
Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken);
|
||||
Task<List<ChannelInfo>> GetChannelsFromListingsProviderData(string id, CancellationToken cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user