mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 09:34:44 +01:00
Make some methods async
This commit is contained in:
@@ -746,12 +746,21 @@ namespace Emby.Server.Implementations.Channels
|
||||
// null if came from cache
|
||||
if (itemsResult != null)
|
||||
{
|
||||
var internalItems = itemsResult.Items
|
||||
.Select(i => GetChannelItemEntity(i, channelProvider, channel.Id, parentItem, cancellationToken))
|
||||
.ToArray();
|
||||
var items = itemsResult.Items;
|
||||
var itemsLen = items.Count;
|
||||
var internalItems = new Guid[itemsLen];
|
||||
for (int i = 0; i < itemsLen; i++)
|
||||
{
|
||||
internalItems[i] = (await GetChannelItemEntityAsync(
|
||||
items[i],
|
||||
channelProvider,
|
||||
channel.Id,
|
||||
parentItem,
|
||||
cancellationToken).ConfigureAwait(false)).Id;
|
||||
}
|
||||
|
||||
var existingIds = _libraryManager.GetItemIds(query);
|
||||
var deadIds = existingIds.Except(internalItems.Select(i => i.Id))
|
||||
var deadIds = existingIds.Except(internalItems)
|
||||
.ToArray();
|
||||
|
||||
foreach (var deadId in deadIds)
|
||||
@@ -963,7 +972,7 @@ namespace Emby.Server.Implementations.Channels
|
||||
return item;
|
||||
}
|
||||
|
||||
private BaseItem GetChannelItemEntity(ChannelItemInfo info, IChannel channelProvider, Guid internalChannelId, BaseItem parentFolder, CancellationToken cancellationToken)
|
||||
private async Task<BaseItem> GetChannelItemEntityAsync(ChannelItemInfo info, IChannel channelProvider, Guid internalChannelId, BaseItem parentFolder, CancellationToken cancellationToken)
|
||||
{
|
||||
var parentFolderId = parentFolder.Id;
|
||||
|
||||
@@ -1165,7 +1174,7 @@ namespace Emby.Server.Implementations.Channels
|
||||
}
|
||||
else if (forceUpdate)
|
||||
{
|
||||
item.UpdateToRepository(ItemUpdateType.None, cancellationToken);
|
||||
await item.UpdateToRepositoryAsync(ItemUpdateType.None, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if ((isNew || forceUpdate) && info.Type == ChannelItemType.Media)
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace Emby.Server.Implementations.Collections
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public BoxSet CreateCollection(CollectionCreationOptions options)
|
||||
public async Task<BoxSet> CreateCollectionAsync(CollectionCreationOptions options)
|
||||
{
|
||||
var name = options.Name;
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Emby.Server.Implementations.Collections
|
||||
// This could cause it to get re-resolved as a plain folder
|
||||
var folderName = _fileSystem.GetValidFilename(name) + " [boxset]";
|
||||
|
||||
var parentFolder = GetCollectionsFolder(true).GetAwaiter().GetResult();
|
||||
var parentFolder = await GetCollectionsFolder(true).ConfigureAwait(false);
|
||||
|
||||
if (parentFolder == null)
|
||||
{
|
||||
@@ -169,12 +169,16 @@ namespace Emby.Server.Implementations.Collections
|
||||
|
||||
if (options.ItemIdList.Length > 0)
|
||||
{
|
||||
AddToCollection(collection.Id, options.ItemIdList, false, new MetadataRefreshOptions(new DirectoryService(_fileSystem))
|
||||
{
|
||||
// The initial adding of items is going to create a local metadata file
|
||||
// This will cause internet metadata to be skipped as a result
|
||||
MetadataRefreshMode = MetadataRefreshMode.FullRefresh
|
||||
});
|
||||
await AddToCollectionAsync(
|
||||
collection.Id,
|
||||
options.ItemIdList.Select(x => new Guid(x)),
|
||||
false,
|
||||
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
|
||||
{
|
||||
// The initial adding of items is going to create a local metadata file
|
||||
// This will cause internet metadata to be skipped as a result
|
||||
MetadataRefreshMode = MetadataRefreshMode.FullRefresh
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -197,18 +201,10 @@ namespace Emby.Server.Implementations.Collections
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddToCollection(Guid collectionId, IEnumerable<string> ids)
|
||||
{
|
||||
AddToCollection(collectionId, ids, true, new MetadataRefreshOptions(new DirectoryService(_fileSystem)));
|
||||
}
|
||||
public Task AddToCollectionAsync(Guid collectionId, IEnumerable<Guid> ids)
|
||||
=> AddToCollectionAsync(collectionId, ids, true, new MetadataRefreshOptions(new DirectoryService(_fileSystem)));
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddToCollection(Guid collectionId, IEnumerable<Guid> ids)
|
||||
{
|
||||
AddToCollection(collectionId, ids.Select(i => i.ToString("N", CultureInfo.InvariantCulture)), true, new MetadataRefreshOptions(new DirectoryService(_fileSystem)));
|
||||
}
|
||||
|
||||
private void AddToCollection(Guid collectionId, IEnumerable<string> ids, bool fireEvent, MetadataRefreshOptions refreshOptions)
|
||||
private async Task AddToCollectionAsync(Guid collectionId, IEnumerable<Guid> ids, bool fireEvent, MetadataRefreshOptions refreshOptions)
|
||||
{
|
||||
var collection = _libraryManager.GetItemById(collectionId) as BoxSet;
|
||||
if (collection == null)
|
||||
@@ -224,15 +220,14 @@ namespace Emby.Server.Implementations.Collections
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var guidId = new Guid(id);
|
||||
var item = _libraryManager.GetItemById(guidId);
|
||||
var item = _libraryManager.GetItemById(id);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentException("No item exists with the supplied Id");
|
||||
}
|
||||
|
||||
if (!currentLinkedChildrenIds.Contains(guidId))
|
||||
if (!currentLinkedChildrenIds.Contains(id))
|
||||
{
|
||||
itemList.Add(item);
|
||||
|
||||
@@ -249,7 +244,7 @@ namespace Emby.Server.Implementations.Collections
|
||||
|
||||
collection.UpdateRatingToItems(linkedChildrenList);
|
||||
|
||||
collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
|
||||
await collection.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
refreshOptions.ForceSave = true;
|
||||
_providerManager.QueueRefresh(collection.Id, refreshOptions, RefreshPriority.High);
|
||||
@@ -266,13 +261,7 @@ namespace Emby.Server.Implementations.Collections
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveFromCollection(Guid collectionId, IEnumerable<string> itemIds)
|
||||
{
|
||||
RemoveFromCollection(collectionId, itemIds.Select(i => new Guid(i)));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveFromCollection(Guid collectionId, IEnumerable<Guid> itemIds)
|
||||
public async Task RemoveFromCollectionAsync(Guid collectionId, IEnumerable<Guid> itemIds)
|
||||
{
|
||||
var collection = _libraryManager.GetItemById(collectionId) as BoxSet;
|
||||
|
||||
@@ -309,7 +298,7 @@ namespace Emby.Server.Implementations.Collections
|
||||
collection.LinkedChildren = collection.LinkedChildren.Except(list).ToArray();
|
||||
}
|
||||
|
||||
collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
|
||||
await collection.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
_providerManager.QueueRefresh(
|
||||
collection.Id,
|
||||
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
|
||||
|
||||
@@ -771,7 +771,7 @@ namespace Emby.Server.Implementations.Library
|
||||
if (folder.ParentId != rootFolder.Id)
|
||||
{
|
||||
folder.ParentId = rootFolder.Id;
|
||||
folder.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None);
|
||||
folder.UpdateToRepositoryAsync(ItemUpdateType.MetadataImport, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
rootFolder.AddVirtualChild(folder);
|
||||
@@ -1868,7 +1868,8 @@ namespace Emby.Server.Implementations.Library
|
||||
return image.Path != null && !image.IsLocalFile;
|
||||
}
|
||||
|
||||
public void UpdateImages(BaseItem item, bool forceUpdate = false)
|
||||
/// <inheritdoc />
|
||||
public async Task UpdateImagesAsync(BaseItem item, bool forceUpdate = false)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
@@ -1891,7 +1892,7 @@ namespace Emby.Server.Implementations.Library
|
||||
try
|
||||
{
|
||||
var index = item.GetImageIndex(img);
|
||||
image = ConvertImageToLocal(item, img, index).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
image = await ConvertImageToLocal(item, img, index).ConfigureAwait(false);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
@@ -1913,7 +1914,7 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Cannnot get image dimensions for {0}", image.Path);
|
||||
_logger.LogError(ex, "Cannot get image dimensions for {0}", image.Path);
|
||||
image.Width = 0;
|
||||
image.Height = 0;
|
||||
continue;
|
||||
@@ -1943,10 +1944,8 @@ namespace Emby.Server.Implementations.Library
|
||||
RegisterItem(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the item.
|
||||
/// </summary>
|
||||
public void UpdateItems(IReadOnlyList<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||
/// <inheritdoc />
|
||||
public async Task UpdateItemsAsync(IReadOnlyList<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
@@ -1957,7 +1956,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
item.DateLastSaved = DateTime.UtcNow;
|
||||
|
||||
UpdateImages(item, updateReason >= ItemUpdateType.ImageUpdate);
|
||||
await UpdateImagesAsync(item, updateReason >= ItemUpdateType.ImageUpdate).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_itemRepository.SaveItems(items, cancellationToken);
|
||||
@@ -1991,17 +1990,9 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="parent">The parent item.</param>
|
||||
/// <param name="updateReason">The update reason.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public void UpdateItem(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||
{
|
||||
UpdateItems(new[] { item }, parent, updateReason, cancellationToken);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public Task UpdateItemAsync(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||
=> UpdateItemsAsync(new[] { item }, parent, updateReason, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Reports the item removed.
|
||||
@@ -2233,7 +2224,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
if (refresh)
|
||||
{
|
||||
item.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None);
|
||||
item.UpdateToRepositoryAsync(ItemUpdateType.MetadataImport, CancellationToken.None).GetAwaiter().GetResult();
|
||||
ProviderManager.QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.Normal);
|
||||
}
|
||||
|
||||
@@ -2420,7 +2411,7 @@ namespace Emby.Server.Implementations.Library
|
||||
if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
item.ViewType = viewType;
|
||||
item.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
|
||||
item.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval;
|
||||
@@ -2902,7 +2893,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
await ProviderManager.SaveImage(item, url, image.Type, imageIndex, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
||||
await item.UpdateToRepositoryAsync(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
return item.GetImageInfo(image.Type, imageIndex);
|
||||
}
|
||||
@@ -2920,7 +2911,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
// Remove this image to prevent it from retrying over and over
|
||||
item.RemoveImage(image);
|
||||
item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
||||
await item.UpdateToRepositoryAsync(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
}
|
||||
}
|
||||
|
||||
private LiveTvChannel GetChannel(ChannelInfo channelInfo, string serviceName, BaseItem parentFolder, CancellationToken cancellationToken)
|
||||
private async Task<LiveTvChannel> GetChannelAsync(ChannelInfo channelInfo, string serviceName, BaseItem parentFolder, CancellationToken cancellationToken)
|
||||
{
|
||||
var parentFolderId = parentFolder.Id;
|
||||
var isNew = false;
|
||||
@@ -512,7 +512,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
}
|
||||
else if (forceUpdate)
|
||||
{
|
||||
_libraryManager.UpdateItem(item, parentFolder, ItemUpdateType.MetadataImport, cancellationToken);
|
||||
await _libraryManager.UpdateItemAsync(item, parentFolder, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return item;
|
||||
@@ -1129,7 +1129,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
|
||||
try
|
||||
{
|
||||
var item = GetChannel(channelInfo.Item2, channelInfo.Item1, parentFolder, cancellationToken);
|
||||
var item = await GetChannelAsync(channelInfo.Item2, channelInfo.Item1, parentFolder, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
list.Add(item);
|
||||
}
|
||||
@@ -1146,7 +1146,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
double percent = numComplete;
|
||||
percent /= allChannelsList.Count;
|
||||
|
||||
progress.Report(5 * percent + 10);
|
||||
progress.Report((5 * percent) + 10);
|
||||
}
|
||||
|
||||
progress.Report(15);
|
||||
@@ -1221,7 +1221,11 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
|
||||
if (updatedPrograms.Count > 0)
|
||||
{
|
||||
_libraryManager.UpdateItems(updatedPrograms, currentChannel, ItemUpdateType.MetadataImport, cancellationToken);
|
||||
await _libraryManager.UpdateItemsAsync(
|
||||
updatedPrograms,
|
||||
currentChannel,
|
||||
ItemUpdateType.MetadataImport,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
currentChannel.IsMovie = isMovie;
|
||||
@@ -1234,7 +1238,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
currentChannel.AddTag("Kids");
|
||||
}
|
||||
|
||||
currentChannel.UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken);
|
||||
await currentChannel.UpdateToRepositoryAsync(ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
|
||||
await currentChannel.RefreshMetadata(
|
||||
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
|
||||
{
|
||||
|
||||
@@ -184,17 +184,17 @@ namespace Emby.Server.Implementations.Playlists
|
||||
return Playlist.GetPlaylistItems(playlistMediaType, items, user, options);
|
||||
}
|
||||
|
||||
public void AddToPlaylist(string playlistId, ICollection<Guid> itemIds, Guid userId)
|
||||
public Task AddToPlaylistAsync(string playlistId, ICollection<Guid> itemIds, Guid userId)
|
||||
{
|
||||
var user = userId.Equals(Guid.Empty) ? null : _userManager.GetUserById(userId);
|
||||
|
||||
AddToPlaylistInternal(playlistId, itemIds, user, new DtoOptions(false)
|
||||
return AddToPlaylistInternal(playlistId, itemIds, user, new DtoOptions(false)
|
||||
{
|
||||
EnableImages = true
|
||||
});
|
||||
}
|
||||
|
||||
private void AddToPlaylistInternal(string playlistId, ICollection<Guid> newItemIds, User user, DtoOptions options)
|
||||
private async Task AddToPlaylistInternal(string playlistId, ICollection<Guid> newItemIds, User user, DtoOptions options)
|
||||
{
|
||||
// Retrieve the existing playlist
|
||||
var playlist = _libraryManager.GetItemById(playlistId) as Playlist
|
||||
@@ -238,7 +238,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
|
||||
// Update the playlist in the repository
|
||||
playlist.LinkedChildren = newLinkedChildren;
|
||||
playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
|
||||
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
// Update the playlist on disk
|
||||
if (playlist.IsFile)
|
||||
@@ -256,7 +256,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
RefreshPriority.High);
|
||||
}
|
||||
|
||||
public void RemoveFromPlaylist(string playlistId, IEnumerable<string> entryIds)
|
||||
public async Task RemoveFromPlaylistAsync(string playlistId, IEnumerable<string> entryIds)
|
||||
{
|
||||
if (!(_libraryManager.GetItemById(playlistId) is Playlist playlist))
|
||||
{
|
||||
@@ -273,7 +273,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
.Select(i => i.Item1)
|
||||
.ToArray();
|
||||
|
||||
playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
|
||||
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
if (playlist.IsFile)
|
||||
{
|
||||
@@ -289,7 +289,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
RefreshPriority.High);
|
||||
}
|
||||
|
||||
public void MoveItem(string playlistId, string entryId, int newIndex)
|
||||
public async Task MoveItemAsync(string playlistId, string entryId, int newIndex)
|
||||
{
|
||||
if (!(_libraryManager.GetItemById(playlistId) is Playlist playlist))
|
||||
{
|
||||
@@ -322,7 +322,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
|
||||
playlist.LinkedChildren = newList.ToArray();
|
||||
|
||||
playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
|
||||
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
if (playlist.IsFile)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user