aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Library/LibraryManager.cs
diff options
context:
space:
mode:
authorVasily <just.one.man@yandex.ru>2020-05-19 14:50:14 +0300
committerVasily <just.one.man@yandex.ru>2020-05-19 14:50:14 +0300
commita226a4ee03d974615a6fa26b936a93458a255b70 (patch)
tree112f24683c4966c12c054288363d7731d90bfd05 /Emby.Server.Implementations/Library/LibraryManager.cs
parentf18293bf762c86581153ab8d9b1b6267421178a9 (diff)
Compute hash only when one is not computed in DB, small optimizations here and there
Diffstat (limited to 'Emby.Server.Implementations/Library/LibraryManager.cs')
-rw-r--r--Emby.Server.Implementations/Library/LibraryManager.cs59
1 files changed, 20 insertions, 39 deletions
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs
index e1cb282cc..c48664a31 100644
--- a/Emby.Server.Implementations/Library/LibraryManager.cs
+++ b/Emby.Server.Implementations/Library/LibraryManager.cs
@@ -1825,17 +1825,26 @@ namespace Emby.Server.Implementations.Library
public void UpdateImages(BaseItem item)
{
- item.ImageInfos
- .Where(i => (i.Width == 0 || i.Height == 0))
- .ToList()
- .ForEach(x =>
- {
- string blurhash = ImageProcessor.GetImageHash(x.Path);
- ImageDimensions size = ImageProcessor.GetImageDimensions(item, x);
- x.Width = size.Width;
- x.Height = size.Height;
- x.Hash = blurhash;
- });
+ if (item == null)
+ {
+ throw new ArgumentNullException(nameof(item));
+ }
+
+ var outdated = item.ImageInfos
+ .Where(i => (i.Width == 0 || i.Height == 0 || string.IsNullOrEmpty(i.Hash)))
+ .ToList();
+ if (outdated.Count == 0)
+ {
+ return;
+ }
+
+ outdated.ForEach(img =>
+ {
+ ImageDimensions size = ImageProcessor.GetImageDimensions(item, img);
+ img.Width = size.Width;
+ img.Height = size.Height;
+ img.Hash = ImageProcessor.GetImageHash(img.Path);
+ });
_itemRepository.SaveImages(item);
@@ -1906,34 +1915,6 @@ namespace Emby.Server.Implementations.Library
}
/// <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>
/// <param name="item">The item.</param>