Add endpoint to update all items in library

pull/2676/head
Jesús Higueras 5 years ago committed by Vasily
parent b9fc0d2628
commit fe480caf54

@ -1911,6 +1911,34 @@ namespace Emby.Server.Implementations.Library
UpdateItems(new[] { item }, parent, updateReason, cancellationToken); 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> /// <summary>
/// Reports the item removed. /// Reports the item removed.
/// </summary> /// </summary>

@ -198,6 +198,12 @@ namespace MediaBrowser.Api
public void Post(UpdateItem request) 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 item = _libraryManager.GetItemById(request.ItemId);
var newLockData = request.LockData ?? false; var newLockData = request.LockData ?? false;

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

Loading…
Cancel
Save