mirror of https://github.com/jellyfin/jellyfin
Library: Async the SaveImages function (#15718)
This commit is contained in:
parent
4db0ab0f40
commit
771b0a7eab
|
|
@ -2143,7 +2143,7 @@ namespace Emby.Server.Implementations.Library
|
||||||
|
|
||||||
item.ValidateImages();
|
item.ValidateImages();
|
||||||
|
|
||||||
_itemRepository.SaveImages(item);
|
await _itemRepository.SaveImagesAsync(item).ConfigureAwait(false);
|
||||||
|
|
||||||
RegisterItem(item);
|
RegisterItem(item);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -547,22 +547,34 @@ public sealed class BaseItemRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void SaveImages(BaseItemDto item)
|
public async Task SaveImagesAsync(BaseItemDto item, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(item);
|
ArgumentNullException.ThrowIfNull(item);
|
||||||
|
|
||||||
var images = item.ImageInfos.Select(e => Map(item.Id, e));
|
var images = item.ImageInfos.Select(e => Map(item.Id, e)).ToArray();
|
||||||
using var context = _dbProvider.CreateDbContext();
|
|
||||||
|
|
||||||
if (!context.BaseItems.Any(bi => bi.Id == item.Id))
|
var context = await _dbProvider.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
await using (context.ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Unable to save ImageInfo for non existing BaseItem");
|
if (!await context.BaseItems
|
||||||
return;
|
.AnyAsync(bi => bi.Id == item.Id, cancellationToken)
|
||||||
}
|
.ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Unable to save ImageInfo for non existing BaseItem");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
context.BaseItemImageInfos.Where(e => e.ItemId == item.Id).ExecuteDelete();
|
await context.BaseItemImageInfos
|
||||||
context.BaseItemImageInfos.AddRange(images);
|
.Where(e => e.ItemId == item.Id)
|
||||||
context.SaveChanges();
|
.ExecuteDeleteAsync(cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
await context.BaseItemImageInfos
|
||||||
|
.AddRangeAsync(images, cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public interface IItemRepository
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
void SaveItems(IReadOnlyList<BaseItem> items, CancellationToken cancellationToken);
|
void SaveItems(IReadOnlyList<BaseItem> items, CancellationToken cancellationToken);
|
||||||
|
|
||||||
void SaveImages(BaseItem item);
|
Task SaveImagesAsync(BaseItem item, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the item.
|
/// Retrieves the item.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue