This commit is contained in:
cvium 2020-12-10 14:47:47 +01:00
parent dd238937f4
commit 3f6e6c4839
3 changed files with 24 additions and 22 deletions

View File

@ -42,7 +42,6 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Library;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Providers.MediaInfo;
@ -1957,7 +1956,10 @@ namespace Emby.Server.Implementations.Library
/// <inheritdoc />
public async Task UpdateItemsAsync(IReadOnlyList<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
{
await RunMetadataSavers(items, updateReason).ConfigureAwait(false);
foreach (var item in items)
{
await RunMetadataSavers(item, updateReason).ConfigureAwait(false);
}
_itemRepository.SaveItems(items, cancellationToken);
@ -1994,19 +1996,16 @@ namespace Emby.Server.Implementations.Library
public Task UpdateItemAsync(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
=> UpdateItemsAsync(new[] { item }, parent, updateReason, cancellationToken);
public async Task RunMetadataSavers(IReadOnlyList<BaseItem> items, ItemUpdateType updateReason)
public Task RunMetadataSavers(BaseItem item, ItemUpdateType updateReason)
{
foreach (var item in items)
if (item.IsFileProtocol)
{
if (item.IsFileProtocol)
{
ProviderManager.SaveMetadata(item, updateReason);
}
item.DateLastSaved = DateTime.UtcNow;
await UpdateImagesAsync(item, updateReason >= ItemUpdateType.ImageUpdate).ConfigureAwait(false);
ProviderManager.SaveMetadata(item, updateReason);
}
item.DateLastSaved = DateTime.UtcNow;
return UpdateImagesAsync(item, updateReason >= ItemUpdateType.ImageUpdate);
}
/// <summary>

View File

@ -571,7 +571,7 @@ namespace MediaBrowser.Controller.Library
string videoPath,
string[] files);
Task RunMetadataSavers(IReadOnlyList<BaseItem> items, ItemUpdateType updateReason);
Task RunMetadataSavers(BaseItem item, ItemUpdateType updateReason);
BaseItem GetParentItem(string parentId, Guid? userId);

View File

@ -232,7 +232,6 @@ namespace MediaBrowser.Providers.Manager
private async Task SavePeopleMetadataAsync(List<PersonInfo> people, LibraryOptions libraryOptions, CancellationToken cancellationToken)
{
var personsToSave = new List<BaseItem>();
var personsToSaveWithImages = new List<BaseItem>();
foreach (var person in people)
{
@ -240,13 +239,15 @@ namespace MediaBrowser.Providers.Manager
if (person.ProviderIds.Count > 0 || !string.IsNullOrWhiteSpace(person.ImageUrl))
{
var itemUpdateType = ItemUpdateType.MetadataDownload;
var saveEntity = false;
var personEntity = LibraryManager.GetPerson(person.Name);
foreach (var id in person.ProviderIds)
{
if (!string.Equals(personEntity.GetProviderId(id.Key), id.Value, StringComparison.OrdinalIgnoreCase))
{
personEntity.SetProviderId(id.Key, id.Value);
personsToSave.Add(personEntity);
saveEntity = true;
}
}
@ -260,17 +261,19 @@ namespace MediaBrowser.Providers.Manager
},
0);
personsToSaveWithImages.Add(personEntity);
saveEntity = true;
itemUpdateType = ItemUpdateType.ImageUpdate;
}
if (saveEntity)
{
personsToSave.Add(personEntity);
await LibraryManager.RunMetadataSavers(personEntity, itemUpdateType).ConfigureAwait(false);
}
}
}
// This is a little ugly, but it saves a lot of I/O with the db by doing this in bulk.
// To avoid updating images for no reason, we differentiate between the two item update types.
await LibraryManager.RunMetadataSavers(personsToSave, ItemUpdateType.MetadataDownload).ConfigureAwait(false);
await LibraryManager.RunMetadataSavers(personsToSaveWithImages, ItemUpdateType.ImageUpdate).ConfigureAwait(false);
LibraryManager.CreateItems(personsToSave.Concat(personsToSaveWithImages).ToList(), null, CancellationToken.None);
LibraryManager.CreateItems(personsToSave, null, CancellationToken.None);
}
protected virtual Task AfterMetadataRefresh(TItemType item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)