Add endpoint to update all items in library

This commit is contained in:
Jesús Higueras 2020-03-25 17:26:53 +01:00 committed by Vasily
parent b9fc0d2628
commit fe480caf54
3 changed files with 35 additions and 0 deletions

View File

@ -1911,6 +1911,34 @@ namespace Emby.Server.Implementations.Library
UpdateItems(new[] { item }, parent, updateReason, cancellationToken);
}
/// <summary>
/// Updates everything in the database.
/// </summary>
public void UpdateAll()
{
Task.Run(() =>
{
var items = ItemRepository.GetItemList(new InternalItemsQuery {
Recursive = true
});
foreach (var item in items)
{
_logger.LogDebug("Updating item {Name} ({ItemId})",
item.Name,
item.Id);
try
{
item.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
}
catch (Exception ex)
{
_logger.LogError(ex, "Updating item {ItemId} failed", item.Id);
}
}
_logger.LogDebug("All items have been updated");
});
}
/// <summary>
/// Reports the item removed.
/// </summary>

View File

@ -198,6 +198,12 @@ namespace MediaBrowser.Api
public void Post(UpdateItem request)
{
if (request.ItemId == "*")
{
// Special case: Refresh everything in database. Probably not a great idea to run often.
_libraryManager.UpdateAll();
return;
}
var item = _libraryManager.GetItemById(request.ItemId);
var newLockData = request.LockData ?? false;

View File

@ -196,6 +196,7 @@ namespace MediaBrowser.Controller.Library
/// </summary>
void UpdateItems(IEnumerable<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken);
void UpdateItem(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken);
void UpdateAll();
/// <summary>
/// Retrieves the item.