Compute hash only when one is not computed in DB, small optimizations here and there

This commit is contained in:
Vasily
2020-05-19 14:50:14 +03:00
parent f18293bf76
commit a226a4ee03
5 changed files with 37 additions and 68 deletions

View File

@@ -1141,20 +1141,10 @@ namespace Emby.Server.Implementations.Data
public string ToValueString(ItemImageInfo image)
{
var delimeter = "*";
const string delimeter = "*";
var path = image.Path;
var hash = image.Hash;
if (path == null)
{
path = string.Empty;
}
if (hash == null)
{
hash = string.Empty;
}
var path = image.Path ?? string.Empty;
var hash = image.Hash ?? string.Empty;
return GetPathToSave(path) +
delimeter +

View File

@@ -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);
@@ -1905,34 +1914,6 @@ 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>