Simplify
This commit is contained in:
parent
dd238937f4
commit
3f6e6c4839
|
@ -42,7 +42,6 @@ using MediaBrowser.Model.Dto;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using MediaBrowser.Model.Library;
|
using MediaBrowser.Model.Library;
|
||||||
using MediaBrowser.Model.Net;
|
|
||||||
using MediaBrowser.Model.Querying;
|
using MediaBrowser.Model.Querying;
|
||||||
using MediaBrowser.Model.Tasks;
|
using MediaBrowser.Model.Tasks;
|
||||||
using MediaBrowser.Providers.MediaInfo;
|
using MediaBrowser.Providers.MediaInfo;
|
||||||
|
@ -1957,7 +1956,10 @@ namespace Emby.Server.Implementations.Library
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task UpdateItemsAsync(IReadOnlyList<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
|
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);
|
_itemRepository.SaveItems(items, cancellationToken);
|
||||||
|
|
||||||
|
@ -1994,19 +1996,16 @@ namespace Emby.Server.Implementations.Library
|
||||||
public Task UpdateItemAsync(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
|
public Task UpdateItemAsync(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||||
=> UpdateItemsAsync(new[] { item }, parent, updateReason, 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);
|
||||||
{
|
|
||||||
ProviderManager.SaveMetadata(item, updateReason);
|
|
||||||
}
|
|
||||||
|
|
||||||
item.DateLastSaved = DateTime.UtcNow;
|
|
||||||
|
|
||||||
await UpdateImagesAsync(item, updateReason >= ItemUpdateType.ImageUpdate).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item.DateLastSaved = DateTime.UtcNow;
|
||||||
|
|
||||||
|
return UpdateImagesAsync(item, updateReason >= ItemUpdateType.ImageUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -571,7 +571,7 @@ namespace MediaBrowser.Controller.Library
|
||||||
string videoPath,
|
string videoPath,
|
||||||
string[] files);
|
string[] files);
|
||||||
|
|
||||||
Task RunMetadataSavers(IReadOnlyList<BaseItem> items, ItemUpdateType updateReason);
|
Task RunMetadataSavers(BaseItem item, ItemUpdateType updateReason);
|
||||||
|
|
||||||
BaseItem GetParentItem(string parentId, Guid? userId);
|
BaseItem GetParentItem(string parentId, Guid? userId);
|
||||||
|
|
||||||
|
|
|
@ -232,7 +232,6 @@ namespace MediaBrowser.Providers.Manager
|
||||||
private async Task SavePeopleMetadataAsync(List<PersonInfo> people, LibraryOptions libraryOptions, CancellationToken cancellationToken)
|
private async Task SavePeopleMetadataAsync(List<PersonInfo> people, LibraryOptions libraryOptions, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var personsToSave = new List<BaseItem>();
|
var personsToSave = new List<BaseItem>();
|
||||||
var personsToSaveWithImages = new List<BaseItem>();
|
|
||||||
|
|
||||||
foreach (var person in people)
|
foreach (var person in people)
|
||||||
{
|
{
|
||||||
|
@ -240,13 +239,15 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
if (person.ProviderIds.Count > 0 || !string.IsNullOrWhiteSpace(person.ImageUrl))
|
if (person.ProviderIds.Count > 0 || !string.IsNullOrWhiteSpace(person.ImageUrl))
|
||||||
{
|
{
|
||||||
|
var itemUpdateType = ItemUpdateType.MetadataDownload;
|
||||||
|
var saveEntity = false;
|
||||||
var personEntity = LibraryManager.GetPerson(person.Name);
|
var personEntity = LibraryManager.GetPerson(person.Name);
|
||||||
foreach (var id in person.ProviderIds)
|
foreach (var id in person.ProviderIds)
|
||||||
{
|
{
|
||||||
if (!string.Equals(personEntity.GetProviderId(id.Key), id.Value, StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(personEntity.GetProviderId(id.Key), id.Value, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
personEntity.SetProviderId(id.Key, id.Value);
|
personEntity.SetProviderId(id.Key, id.Value);
|
||||||
personsToSave.Add(personEntity);
|
saveEntity = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,17 +261,19 @@ namespace MediaBrowser.Providers.Manager
|
||||||
},
|
},
|
||||||
0);
|
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.
|
LibraryManager.CreateItems(personsToSave, null, CancellationToken.None);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Task AfterMetadataRefresh(TItemType item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
|
protected virtual Task AfterMetadataRefresh(TItemType item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user