The Free Software Media System - Server Backend & API
Minor perf improvements
Bond_009b21919c7f407
diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.csindex 2991861129..5f25b8cdc0 100644--- a/Emby.Dlna/ContentDirectory/ControlHandler.cs+++ b/Emby.Dlna/ContentDirectory/ControlHandler.cs@@ -1346,8 +1346,8 @@ namespace Emby.Dlna.ContentDirectory{if (id.StartsWith(name + "_", StringComparison.OrdinalIgnoreCase)){- stubType = (StubType)Enum.Parse(typeof(StubType), name, true);- id = id.Split(new[] { '_' }, 2)[1];+ stubType = Enum.Parse<StubType>(name, true);+ id = id.Split('_', 2)[1];break;}diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.csindex 5b8a89d8f3..abaf522bca 100644--- a/Emby.Dlna/Didl/DidlBuilder.cs+++ b/Emby.Dlna/Didl/DidlBuilder.cs@@ -123,7 +123,7 @@ namespace Emby.Dlna.Didl{foreach (var att in profile.XmlRootAttributes){- var parts = att.Name.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);+ var parts = att.Name.Split(':', StringSplitOptions.RemoveEmptyEntries);if (parts.Length == 2){writer.WriteAttributeString(parts[0], parts[1], null, att.Value);diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.csindex 1807ac6a13..069400833e 100644--- a/Emby.Dlna/DlnaManager.cs+++ b/Emby.Dlna/DlnaManager.cs@@ -383,9 +383,9 @@ namespace Emby.Dlnacontinue;}- var filename = Path.GetFileName(name).Substring(namespaceName.Length);-- var path = Path.Combine(systemProfilesPath, filename);+ var path = Path.Join(+ systemProfilesPath,+ Path.GetFileName(name.AsSpan()).Slice(namespaceName.Length));using (var stream = _assembly.GetManifestResourceStream(name)){diff --git a/Emby.Dlna/Eventing/DlnaEventManager.cs b/Emby.Dlna/Eventing/DlnaEventManager.csindex 7d8da86ef9..770d56c30f 100644--- a/Emby.Dlna/Eventing/DlnaEventManager.cs+++ b/Emby.Dlna/Eventing/DlnaEventManager.cs@@ -168,7 +168,7 @@ namespace Emby.Dlna.Eventingbuilder.Append("</e:propertyset>");- using var options = new HttpRequestMessage(new HttpMethod("NOTIFY"), subscription.CallbackUrl);+ using var options = new HttpRequestMessage(new HttpMethod("NOTIFY"), subscription.CallbackUrl);options.Content = new StringContent(builder.ToString(), Encoding.UTF8, MediaTypeNames.Text.Xml);options.Headers.TryAddWithoutValidation("NT", subscription.NotificationType);options.Headers.TryAddWithoutValidation("NTS", "upnp:propchange");diff --git a/Emby.Dlna/Main/DlnaEntryPoint.cs b/Emby.Dlna/Main/DlnaEntryPoint.csindex 40c2cc0e0a..f8a00efaca 100644--- a/Emby.Dlna/Main/DlnaEntryPoint.cs+++ b/Emby.Dlna/Main/DlnaEntryPoint.cs@@ -257,9 +257,10 @@ namespace Emby.Dlna.Mainprivate async Task RegisterServerEndpoints(){- var addresses = await _appHost.GetLocalIpAddresses(CancellationToken.None).ConfigureAwait(false);+ var addresses = await _appHost.GetLocalIpAddresses().ConfigureAwait(false);var udn = CreateUuid(_appHost.SystemId);+ var descriptorUri = "/dlna/" + udn + "/description.xml";foreach (var address in addresses){@@ -279,7 +280,6 @@ namespace Emby.Dlna.Main_logger.LogInformation("Registering publisher for {0} on {1}", fullService, address);- var descriptorUri = "/dlna/" + udn + "/description.xml";var uri = new Uri(_appHost.GetLocalApiUrl(address) + descriptorUri);var device = new SsdpRootDevicediff --git a/Emby.Dlna/PlayTo/PlayToController.cs b/Emby.Dlna/PlayTo/PlayToController.csindex a5b8e2b3ce..c07c8aefa6 100644--- a/Emby.Dlna/PlayTo/PlayToController.cs+++ b/Emby.Dlna/PlayTo/PlayToController.cs@@ -326,7 +326,7 @@ namespace Emby.Dlna.PlayTopublic Task SendPlayCommand(PlayRequest command, CancellationToken cancellationToken){- _logger.LogDebug("{0} - Received PlayRequest: {1}", this._session.DeviceName, command.PlayCommand);+ _logger.LogDebug("{0} - Received PlayRequest: {1}", _session.DeviceName, command.PlayCommand);var user = command.ControllingUserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(command.ControllingUserId);@@ -339,7 +339,7 @@ namespace Emby.Dlna.PlayTovar startIndex = command.StartIndex ?? 0;if (startIndex > 0){- items = items.Skip(startIndex).ToList();+ items = items.GetRange(startIndex, items.Count - startIndex);}var playlist = new List<PlaylistItem>();diff --git a/Emby.Notifications/NotificationEntryPoint.cs b/Emby.Notifications/NotificationEntryPoint.csindex ded22d26cc..7116d52b11 100644--- a/Emby.Notifications/NotificationEntryPoint.cs+++ b/Emby.Notifications/NotificationEntryPoint.cs@@ -209,7 +209,10 @@ namespace Emby.Notifications_libraryUpdateTimer = null;}- items = items.Take(10).ToList();+ if (items.Count > 10)+ {+ items = items.GetRange(0, 10);+ }foreach (var item in items){diff --git a/Emby.Server.Implementations/Channels/ChannelManager.cs b/Emby.Server.Implementations/Channels/ChannelManager.csindex db44bf4898..19045b72b4 100644--- a/Emby.Server.Implementations/Channels/ChannelManager.cs+++ b/Emby.Server.Implementations/Channels/ChannelManager.cs@@ -250,21 +250,16 @@ namespace Emby.Server.Implementations.Channelsvar all = channels;var totalCount = all.Count;- if (query.StartIndex.HasValue)+ if (query.StartIndex.HasValue || query.Limit.HasValue){- all = all.Skip(query.StartIndex.Value).ToList();+ int startIndex = query.StartIndex ?? 0;+ int count = query.Limit == null ? totalCount - startIndex : Math.Min(query.Limit.Value, totalCount - startIndex);+ all = all.GetRange(startIndex, count);}- if (query.Limit.HasValue)- {- all = all.Take(query.Limit.Value).ToList();- }-- var returnItems = all.ToArray();-if (query.RefreshLatestChannelItems){- foreach (var item in returnItems)+ foreach (var item in all){RefreshLatestChannelItems(GetChannelProvider(item), CancellationToken.None).GetAwaiter().GetResult();}@@ -272,7 +267,7 @@ namespace Emby.Server.Implementations.Channelsreturn new QueryResult<Channel>{- Items = returnItems,+ Items = all,TotalRecordCount = totalCount};}diff --git a/Jellyfin.Api/Controllers/InstantMixController.cs b/Jellyfin.Api/Controllers/InstantMixController.csindex e6e6b3e70e..7682ceff3e 100644--- a/Jellyfin.Api/Controllers/InstantMixController.cs+++ b/Jellyfin.Api/Controllers/InstantMixController.cs@@ -316,9 +316,9 @@ namespace Jellyfin.Api.ControllersTotalRecordCount = list.Count};- if (limit.HasValue)+ if (limit.HasValue && limit > list.Count){- list = list.Take(limit.Value).ToList();+ list = list.GetRange(0, limit.Value);}var returnList = _dtoService.GetBaseItemDtos(list, dtoOptions, user);diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.csindex a219a74cf8..924ae04778 100644--- a/Jellyfin.Api/Controllers/UniversalAudioController.cs+++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs@@ -268,20 +268,24 @@ namespace Jellyfin.Api.Controllers{var deviceProfile = new DeviceProfile();- var directPlayProfiles = new List<DirectPlayProfile>();-var containers = RequestHelpers.Split(container, ',', true);-- foreach (var cont in containers)+ int len = containers.Length;+ var directPlayProfiles = new DirectPlayProfile[len];+ for (int i = 0; i < len; i++){- var parts = RequestHelpers.Split(cont, '|', true);+ var parts = RequestHelpers.Split(containers[i], '|', true);- var audioCodecs = parts.Length == 1 ? null : string.Join(",", parts.Skip(1).ToArray());+ var audioCodecs = parts.Length == 1 ? null : string.Join(',', parts.Skip(1));- directPlayProfiles.Add(new DirectPlayProfile { Type = DlnaProfileType.Audio, Container = parts[0], AudioCodec = audioCodecs });+ directPlayProfiles[i] = new DirectPlayProfile+ {+ Type = DlnaProfileType.Audio,+ Container = parts[0],+ AudioCodec = audioCodecs+ };}- deviceProfile.DirectPlayProfiles = directPlayProfiles.ToArray();+ deviceProfile.DirectPlayProfiles = directPlayProfiles;deviceProfile.TranscodingProfiles = new[]{diff --git a/Jellyfin.Api/Helpers/SimilarItemsHelper.cs b/Jellyfin.Api/Helpers/SimilarItemsHelper.csindex b922e76cfd..f4b654ef01 100644--- a/Jellyfin.Api/Helpers/SimilarItemsHelper.cs+++ b/Jellyfin.Api/Helpers/SimilarItemsHelper.cs@@ -50,9 +50,9 @@ namespace Jellyfin.Api.Helpersvar returnItems = items;- if (limit.HasValue)+ if (limit.HasValue && limit > returnItems.Count){- returnItems = returnItems.Take(limit.Value).ToList();+ returnItems = returnItems.GetRange(0, limit.Value);}var dtos = dtoService.GetBaseItemDtos(returnItems, dtoOptions, user);diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.csindex cfad17fb72..649b0eaec8 100644--- a/MediaBrowser.Controller/IServerApplicationHost.cs+++ b/MediaBrowser.Controller/IServerApplicationHost.cs@@ -56,10 +56,11 @@ namespace MediaBrowser.Controller/// <summary>/// Gets the system info./// </summary>+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the task.</param>/// <returns>SystemInfo.</returns>- Task<SystemInfo> GetSystemInfo(CancellationToken cancellationToken);+ Task<SystemInfo> GetSystemInfo(CancellationToken cancellationToken = default);- Task<PublicSystemInfo> GetPublicSystemInfo(CancellationToken cancellationToken);+ Task<PublicSystemInfo> GetPublicSystemInfo(CancellationToken cancellationToken = default);/// <summary>/// Gets all the local IP addresses of this API instance. Each address is validated by sending a 'ping' request@@ -67,7 +68,7 @@ namespace MediaBrowser.Controller/// </summary>/// <param name="cancellationToken">A cancellation token that can be used to cancel the task.</param>/// <returns>A list containing all the local IP addresses of the server.</returns>- Task<List<IPAddress>> GetLocalIpAddresses(CancellationToken cancellationToken);+ Task<List<IPAddress>> GetLocalIpAddresses(CancellationToken cancellationToken = default);/// <summary>/// Gets a local (LAN) URL that can be used to access the API. The hostname used is the first valid configured@@ -75,7 +76,7 @@ namespace MediaBrowser.Controller/// </summary>/// <param name="cancellationToken">A cancellation token that can be used to cancel the task.</param>/// <returns>The server URL.</returns>- Task<string> GetLocalApiUrl(CancellationToken cancellationToken);+ Task<string> GetLocalApiUrl(CancellationToken cancellationToken = default);/// <summary>/// Gets a localhost URL that can be used to access the API using the loop-back IP address (127.0.0.1)