mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-08-05 08:40:11 -04:00
reduce uses of Task.Run
This commit is contained in:
parent
2b8b98b590
commit
b838c53017
@ -217,7 +217,7 @@ namespace MediaBrowser.Controller.Drawing
|
|||||||
var outputTask = toStream.WriteAsync(bytes, 0, bytes.Length);
|
var outputTask = toStream.WriteAsync(bytes, 0, bytes.Length);
|
||||||
|
|
||||||
// kick off a task to cache the result
|
// kick off a task to cache the result
|
||||||
Task.Run(() => CacheResizedImage(cacheFilePath, bytes));
|
await CacheResizedImage(cacheFilePath, bytes).ConfigureAwait(false);
|
||||||
|
|
||||||
await outputTask.ConfigureAwait(false);
|
await outputTask.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ namespace MediaBrowser.Controller.Drawing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cacheFilePath">The cache file path.</param>
|
/// <param name="cacheFilePath">The cache file path.</param>
|
||||||
/// <param name="bytes">The bytes.</param>
|
/// <param name="bytes">The bytes.</param>
|
||||||
private async void CacheResizedImage(string cacheFilePath, byte[] bytes)
|
private async Task CacheResizedImage(string cacheFilePath, byte[] bytes)
|
||||||
{
|
{
|
||||||
// Save to the cache location
|
// Save to the cache location
|
||||||
using (var cacheFileStream = new FileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
|
using (var cacheFileStream = new FileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
|
||||||
@ -320,7 +320,7 @@ namespace MediaBrowser.Controller.Drawing
|
|||||||
var size = ImageHeader.GetDimensions(imagePath, _logger);
|
var size = ImageHeader.GetDimensions(imagePath, _logger);
|
||||||
|
|
||||||
// Update the file system cache
|
// Update the file system cache
|
||||||
Task.Run(() => File.WriteAllText(fullCachePath, size.Width.ToString(UsCulture) + @"|" + size.Height.ToString(UsCulture)));
|
File.WriteAllText(fullCachePath, size.Width.ToString(UsCulture) + @"|" + size.Height.ToString(UsCulture));
|
||||||
|
|
||||||
return new ImageSize { Width = size.Width, Height = size.Height };
|
return new ImageSize { Width = size.Width, Height = size.Height };
|
||||||
}
|
}
|
||||||
|
@ -282,58 +282,54 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RaiseReceiveWebRequest(context);
|
||||||
|
|
||||||
Task.Run(() =>
|
try
|
||||||
{
|
{
|
||||||
RaiseReceiveWebRequest(context);
|
ProcessRequest(context);
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
HandleException(context.Response, ex, 422);
|
||||||
|
|
||||||
try
|
throw;
|
||||||
{
|
}
|
||||||
ProcessRequest(context);
|
catch (ResourceNotFoundException ex)
|
||||||
}
|
{
|
||||||
catch (InvalidOperationException ex)
|
HandleException(context.Response, ex, 404);
|
||||||
{
|
|
||||||
HandleException(context.Response, ex, 422);
|
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (ResourceNotFoundException ex)
|
catch (FileNotFoundException ex)
|
||||||
{
|
{
|
||||||
HandleException(context.Response, ex, 404);
|
HandleException(context.Response, ex, 404);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException ex)
|
catch (DirectoryNotFoundException ex)
|
||||||
{
|
{
|
||||||
HandleException(context.Response, ex, 404);
|
HandleException(context.Response, ex, 404);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (DirectoryNotFoundException ex)
|
catch (UnauthorizedAccessException ex)
|
||||||
{
|
{
|
||||||
HandleException(context.Response, ex, 404);
|
HandleException(context.Response, ex, 401);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException ex)
|
catch (ArgumentException ex)
|
||||||
{
|
{
|
||||||
HandleException(context.Response, ex, 401);
|
HandleException(context.Response, ex, 400);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (ArgumentException ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
HandleException(context.Response, ex, 400);
|
HandleException(context.Response, ex, 500);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
HandleException(context.Response, ex, 500);
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||||||
{
|
{
|
||||||
UpdateLibraryCache(args);
|
UpdateLibraryCache(args);
|
||||||
|
|
||||||
EventHelper.QueueEventIfNotNull(LibraryChanged, this, args, _logger);
|
EventHelper.FireEventIfNotNull(LibraryChanged, this, args, _logger);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -195,17 +195,14 @@ namespace MediaBrowser.Server.Implementations.Sqlite
|
|||||||
throw new ArgumentNullException("cancellationToken");
|
throw new ArgumentNullException("cancellationToken");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.Run(() =>
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
{
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
var cmd = connection.CreateCommand();
|
var cmd = connection.CreateCommand();
|
||||||
cmd.CommandText = "delete from users where guid=@guid";
|
cmd.CommandText = "delete from users where guid=@guid";
|
||||||
var guidParam = cmd.Parameters.Add("@guid", DbType.Guid);
|
var guidParam = cmd.Parameters.Add("@guid", DbType.Guid);
|
||||||
guidParam.Value = user.Id;
|
guidParam.Value = user.Id;
|
||||||
|
|
||||||
return ExecuteCommand(cmd);
|
return ExecuteCommand(cmd);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using Alchemy.Classes;
|
using Alchemy.Classes;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
|
using MediaBrowser.Model.Net;
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Model.Net;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.WebSocket
|
namespace MediaBrowser.Server.Implementations.WebSocket
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user