The Free Software Media System - Server Backend & API
Always await instead of directly returning Task
Bond_009d2db7004024c
diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.csindex cb6f7e1d35..a720c86fb2 100644--- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs+++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs@@ -82,17 +82,17 @@ namespace Emby.Server.Implementations.HttpServerpublic WebSocketState State => _socket.State;/// <inheritdoc />- public Task SendAsync(OutboundWebSocketMessage message, CancellationToken cancellationToken)+ public async Task SendAsync(OutboundWebSocketMessage message, CancellationToken cancellationToken){var json = JsonSerializer.SerializeToUtf8Bytes(message, _jsonOptions);- return _socket.SendAsync(json, WebSocketMessageType.Text, true, cancellationToken);+ await _socket.SendAsync(json, WebSocketMessageType.Text, true, cancellationToken).ConfigureAwait(false);}/// <inheritdoc />- public Task SendAsync<T>(OutboundWebSocketMessage<T> message, CancellationToken cancellationToken)+ public async Task SendAsync<T>(OutboundWebSocketMessage<T> message, CancellationToken cancellationToken){var json = JsonSerializer.SerializeToUtf8Bytes(message, _jsonOptions);- return _socket.SendAsync(json, WebSocketMessageType.Text, true, cancellationToken);+ await _socket.SendAsync(json, WebSocketMessageType.Text, true, cancellationToken).ConfigureAwait(false);}/// <inheritdoc />@@ -224,12 +224,12 @@ namespace Emby.Server.Implementations.HttpServerreturn ret;}- private Task SendKeepAliveResponse()+ private async Task SendKeepAliveResponse(){LastKeepAliveDate = DateTime.UtcNow;- return SendAsync(+ await SendAsync(new OutboundKeepAliveMessage(),- CancellationToken.None);+ CancellationToken.None).ConfigureAwait(false);}/// <inheritdoc />diff --git a/Emby.Server.Implementations/HttpServer/WebSocketManager.cs b/Emby.Server.Implementations/HttpServer/WebSocketManager.csindex 774d3563cb..cb5b3993b8 100644--- a/Emby.Server.Implementations/HttpServer/WebSocketManager.cs+++ b/Emby.Server.Implementations/HttpServer/WebSocketManager.cs@@ -84,7 +84,7 @@ namespace Emby.Server.Implementations.HttpServer/// Processes the web socket message received./// </summary>/// <param name="result">The result.</param>- private Task ProcessWebSocketMessageReceived(WebSocketMessageInfo result)+ private async Task ProcessWebSocketMessageReceived(WebSocketMessageInfo result){var tasks = new Task[_webSocketListeners.Length];for (var i = 0; i < _webSocketListeners.Length; ++i)@@ -92,7 +92,7 @@ namespace Emby.Server.Implementations.HttpServertasks[i] = _webSocketListeners[i].ProcessMessageAsync(result);}- return Task.WhenAll(tasks);+ await Task.WhenAll(tasks).ConfigureAwait(false);}}}diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.csindex aba51de8f5..75a50f7f52 100644--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs@@ -276,11 +276,11 @@ namespace Emby.Server.Implementations.Session/// </summary>/// <param name="webSocket">The WebSocket.</param>/// <returns>Task.</returns>- private Task SendForceKeepAlive(IWebSocketConnection webSocket)+ private async Task SendForceKeepAlive(IWebSocketConnection webSocket){- return webSocket.SendAsync(+ await webSocket.SendAsync(new ForceKeepAliveMessage(WebSocketLostTimeout),- CancellationToken.None);+ CancellationToken.None).ConfigureAwait(false);}}}diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.csindex 54e0527c90..9485927126 100644--- a/Jellyfin.Api/Controllers/DynamicHlsController.cs+++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs@@ -2059,16 +2059,16 @@ public class DynamicHlsController : BaseJellyfinApiController}}- private Task DeleteLastFile(string playlistPath, string segmentExtension, int retryCount)+ private async Task DeleteLastFile(string playlistPath, string segmentExtension, int retryCount){var file = GetLastTranscodingFile(playlistPath, segmentExtension, _fileSystem);if (file is null){- return Task.CompletedTask;+ return;}- return DeleteFile(file.FullName, retryCount);+ await DeleteFile(file.FullName, retryCount).ConfigureAwait(false);}private async Task DeleteFile(string path, int retryCount)diff --git a/Jellyfin.Api/Formatters/CssOutputFormatter.cs b/Jellyfin.Api/Formatters/CssOutputFormatter.csindex 495f771e1f..9ad1c863ea 100644--- a/Jellyfin.Api/Formatters/CssOutputFormatter.cs+++ b/Jellyfin.Api/Formatters/CssOutputFormatter.cs@@ -1,6 +1,4 @@-using System.Text;-using System.Threading.Tasks;-using Microsoft.AspNetCore.Http;+using System.Net.Mime;using Microsoft.AspNetCore.Mvc.Formatters;namespace Jellyfin.Api.Formatters;@@ -8,28 +6,14 @@ namespace Jellyfin.Api.Formatters;/// <summary>/// Css output formatter./// </summary>-public class CssOutputFormatter : TextOutputFormatter+public sealed class CssOutputFormatter : StringOutputFormatter{/// <summary>/// Initializes a new instance of the <see cref="CssOutputFormatter"/> class./// </summary>public CssOutputFormatter(){- SupportedMediaTypes.Add("text/css");-- SupportedEncodings.Add(Encoding.UTF8);- SupportedEncodings.Add(Encoding.Unicode);- }-- /// <summary>- /// Write context object to stream.- /// </summary>- /// <param name="context">Writer context.</param>- /// <param name="selectedEncoding">Unused. Writer encoding.</param>- /// <returns>Write stream task.</returns>- public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)- {- var stringResponse = context.Object?.ToString();- return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse);+ SupportedMediaTypes.Clear();+ SupportedMediaTypes.Add(MediaTypeNames.Text.Css);}}diff --git a/Jellyfin.Api/Formatters/XmlOutputFormatter.cs b/Jellyfin.Api/Formatters/XmlOutputFormatter.csindex 1c9feedcb7..8dbb91d0aa 100644--- a/Jellyfin.Api/Formatters/XmlOutputFormatter.cs+++ b/Jellyfin.Api/Formatters/XmlOutputFormatter.cs@@ -1,7 +1,4 @@using System.Net.Mime;-using System.Text;-using System.Threading.Tasks;-using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc.Formatters;namespace Jellyfin.Api.Formatters;@@ -9,7 +6,7 @@ namespace Jellyfin.Api.Formatters;/// <summary>/// Xml output formatter./// </summary>-public class XmlOutputFormatter : TextOutputFormatter+public sealed class XmlOutputFormatter : StringOutputFormatter{/// <summary>/// Initializes a new instance of the <see cref="XmlOutputFormatter"/> class.@@ -18,15 +15,5 @@ public class XmlOutputFormatter : TextOutputFormatter{SupportedMediaTypes.Clear();SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);-- SupportedEncodings.Add(Encoding.UTF8);- SupportedEncodings.Add(Encoding.Unicode);- }-- /// <inheritdoc />- public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)- {- var stringResponse = context.Object?.ToString();- return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse);}}diff --git a/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs b/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.csindex 801026c549..999e083845 100644--- a/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs+++ b/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs@@ -67,38 +67,40 @@ namespace Jellyfin.Server.Infrastructure}/// <inheritdoc />- protected override Task WriteFileAsync(ActionContext context, PhysicalFileResult result, RangeItemHeaderValue? range, long rangeLength)+ protected override async Task WriteFileAsync(ActionContext context, PhysicalFileResult result, RangeItemHeaderValue? range, long rangeLength){ArgumentNullException.ThrowIfNull(context);ArgumentNullException.ThrowIfNull(result);if (range is not null && rangeLength == 0){- return Task.CompletedTask;+ return;}// It's a bit of wasted IO to perform this check again, but non-symlinks shouldn't use this codeif (!IsSymLink(result.FileName)){- return base.WriteFileAsync(context, result, range, rangeLength);+ await base.WriteFileAsync(context, result, range, rangeLength).ConfigureAwait(false);+ return;}var response = context.HttpContext.Response;if (range is not null){- return SendFileAsync(+ await SendFileAsync(result.FileName,response,offset: range.From ?? 0L,- count: rangeLength);+ count: rangeLength).ConfigureAwait(false);+ return;}- return SendFileAsync(+ await SendFileAsync(result.FileName,response,offset: 0,- count: null);+ count: null).ConfigureAwait(false);}private async Task SendFileAsync(string filePath, HttpResponse response, long offset, long? count)diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.csindex 1ab6c97066..5b7b03de21 100644--- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs+++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs@@ -110,15 +110,15 @@ namespace MediaBrowser.Controller.Entities.Audioreturn base.IsSaveLocalMetadataEnabled();}- protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)+ protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken){if (IsAccessedByName){// Should never get in here anyway- return Task.CompletedTask;+ return;}- return base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, false, refreshOptions, directoryService, cancellationToken);+ await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, false, refreshOptions, directoryService, cancellationToken).ConfigureAwait(false);}public override List<string> GetUserDataKeys()diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.csindex eb605f6c87..a9caa8453a 100644--- a/MediaBrowser.Controller/Entities/BaseItem.cs+++ b/MediaBrowser.Controller/Entities/BaseItem.cs@@ -1977,8 +1977,8 @@ namespace MediaBrowser.Controller.EntitiesImageInfos = [..ImageInfos, image];}- public virtual Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationToken)- => LibraryManager.UpdateItemAsync(this, GetParent(), updateReason, cancellationToken);+ public virtual async Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationToken)+ => await LibraryManager.UpdateItemAsync(this, GetParent(), updateReason, cancellationToken).ConfigureAwait(false);/// <summary>/// Validates that images within the item are still on the filesystem.@@ -2367,7 +2367,7 @@ namespace MediaBrowser.Controller.Entities}}- protected Task RefreshMetadataForOwnedItem(BaseItem ownedItem, bool copyTitleMetadata, MetadataRefreshOptions options, CancellationToken cancellationToken)+ protected async Task RefreshMetadataForOwnedItem(BaseItem ownedItem, bool copyTitleMetadata, MetadataRefreshOptions options, CancellationToken cancellationToken){var newOptions = new MetadataRefreshOptions(options){@@ -2428,10 +2428,10 @@ namespace MediaBrowser.Controller.Entities}}- return ownedItem.RefreshMetadata(newOptions, cancellationToken);+ await ownedItem.RefreshMetadata(newOptions, cancellationToken).ConfigureAwait(false);}- protected Task RefreshMetadataForOwnedVideo(MetadataRefreshOptions options, bool copyTitleMetadata, string path, CancellationToken cancellationToken)+ protected async Task RefreshMetadataForOwnedVideo(MetadataRefreshOptions options, bool copyTitleMetadata, string path, CancellationToken cancellationToken){var newOptions = new MetadataRefreshOptions(options){@@ -2441,9 +2441,7 @@ namespace MediaBrowser.Controller.Entitiesvar id = LibraryManager.GetNewItemId(path, typeof(Video));// Try to retrieve it from the db. If we don't find it, use the resolved version- var video = LibraryManager.GetItemById(id) as Video;-- if (video is null)+ if (LibraryManager.GetItemById(id) is not Video video){video = LibraryManager.ResolvePath(FileSystem.GetFileSystemInfo(path)) as Video;@@ -2452,15 +2450,15 @@ namespace MediaBrowser.Controller.Entitiesif (video is null){- return Task.FromResult(true);+ return;}if (video.OwnerId.IsEmpty()){- video.OwnerId = this.Id;+ video.OwnerId = Id;}- return RefreshMetadataForOwnedItem(video, copyTitleMetadata, newOptions, cancellationToken);+ await RefreshMetadataForOwnedItem(video, copyTitleMetadata, newOptions, cancellationToken).ConfigureAwait(false);}public string GetEtag(User user)diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.csindex 83c19a54e1..41e26fc9ae 100644--- a/MediaBrowser.Controller/Entities/Folder.cs+++ b/MediaBrowser.Controller/Entities/Folder.cs@@ -528,13 +528,13 @@ namespace MediaBrowser.Controller.Entities}}- private Task RefreshMetadataRecursive(IList<BaseItem> children, MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)+ private async Task RefreshMetadataRecursive(IList<BaseItem> children, MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken){- return RunTasks(+ await RunTasks((baseItem, innerProgress) => RefreshChildMetadata(baseItem, refreshOptions, recursive && baseItem.IsFolder, innerProgress, cancellationToken),children,progress,- cancellationToken);+ cancellationToken).ConfigureAwait(false);}private async Task RefreshAllMetadataForContainer(IMetadataContainer container, MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)@@ -575,13 +575,13 @@ namespace MediaBrowser.Controller.Entities/// <param name="progress">The progress.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task.</returns>- private Task ValidateSubFolders(IList<Folder> children, IDirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken)+ private async Task ValidateSubFolders(IList<Folder> children, IDirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken){- return RunTasks(+ await RunTasks((folder, innerProgress) => folder.ValidateChildrenInternal(innerProgress, true, false, false, null, directoryService, cancellationToken),children,progress,- cancellationToken);+ cancellationToken).ConfigureAwait(false);}/// <summary>diff --git a/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.csindex 3f018cae9b..ae767a72ac 100644--- a/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs+++ b/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs@@ -45,16 +45,16 @@ namespace MediaBrowser.LocalMetadata.Savers}/// <inheritdoc />- protected override Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer)+ protected override async Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer){var game = (Playlist)item;if (game.PlaylistMediaType == MediaType.Unknown){- return Task.CompletedTask;+ return;}- return writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType.ToString());+ await writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType.ToString()).ConfigureAwait(false);}/// <inheritdoc />diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AudioDbAlbumProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AudioDbAlbumProvider.csindex daad9706cd..ff30af8797 100644--- a/MediaBrowser.Providers/Plugins/AudioDb/AudioDbAlbumProvider.cs+++ b/MediaBrowser.Providers/Plugins/AudioDb/AudioDbAlbumProvider.cs@@ -148,21 +148,19 @@ namespace MediaBrowser.Providers.Plugins.AudioDbitem.Overview = (overview ?? string.Empty).StripHtml();}- internal Task EnsureInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken)+ internal async Task EnsureInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken){var xmlPath = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId);var fileInfo = _fileSystem.GetFileSystemInfo(xmlPath);- if (fileInfo.Exists)+ if (fileInfo.Exists+ && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2){- if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2)- {- return Task.CompletedTask;- }+ return;}- return DownloadInfo(musicBrainzReleaseGroupId, cancellationToken);+ await DownloadInfo(musicBrainzReleaseGroupId, cancellationToken).ConfigureAwait(false);}internal async Task DownloadInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken)diff --git a/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs b/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.csindex 92742b1aa5..00bd96282c 100644--- a/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs+++ b/MediaBrowser.Providers/Plugins/AudioDb/AudioDbArtistProvider.cs@@ -131,7 +131,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDbitem.Overview = (overview ?? string.Empty).StripHtml();}- internal Task EnsureArtistInfo(string musicBrainzId, CancellationToken cancellationToken)+ internal async Task EnsureArtistInfo(string musicBrainzId, CancellationToken cancellationToken){var xmlPath = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);@@ -140,10 +140,10 @@ namespace MediaBrowser.Providers.Plugins.AudioDbif (fileInfo.Exists&& (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2){- return Task.CompletedTask;+ return;}- return DownloadArtistInfo(musicBrainzId, cancellationToken);+ await DownloadArtistInfo(musicBrainzId, cancellationToken).ConfigureAwait(false);}internal async Task DownloadArtistInfo(string musicBrainzId, CancellationToken cancellationToken)diff --git a/MediaBrowser.Providers/Plugins/StudioImages/StudiosImageProvider.cs b/MediaBrowser.Providers/Plugins/StudioImages/StudiosImageProvider.csindex 5ca9f6f9a4..a50d69df53 100644--- a/MediaBrowser.Providers/Plugins/StudioImages/StudiosImageProvider.cs+++ b/MediaBrowser.Providers/Plugins/StudioImages/StudiosImageProvider.cs@@ -101,11 +101,11 @@ namespace MediaBrowser.Providers.Plugins.StudioImagesreturn string.Format(CultureInfo.InvariantCulture, "{0}/images/{1}/{2}.jpg", GetRepositoryUrl(), image, filename);}- private Task EnsureThumbsList(string file, CancellationToken cancellationToken)+ private async Task EnsureThumbsList(string file, CancellationToken cancellationToken){string url = string.Format(CultureInfo.InvariantCulture, "{0}/thumbs.txt", GetRepositoryUrl());- return EnsureList(url, file, _fileSystem, cancellationToken);+ await EnsureList(url, file, _fileSystem, cancellationToken).ConfigureAwait(false);}/// <inheritdoc />