mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 09:34:44 +01:00
Compute hash only when one is not computed in DB, small optimizations here and there
This commit is contained in:
@@ -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 +
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user