Skip to content

Commit

Permalink
♻️ Do not overwrite cached image files.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed Feb 8, 2025
1 parent db5b84a commit ce9e004
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Exo/Service/Exo.Service.Core/ImageStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ bool shouldApplyCircularMask
TransformImage(stream, image, sourceRectangle, targetFormat, targetSize, shouldStripAnimations, shouldApplyCircularMask);
var physicalImageId = XxHash128.HashToUInt128(stream.GetBuffer().AsSpan(0, (int)stream.Length), PhysicalImageIdHashSeed);
string fileName = GetFileName(_imageCacheDirectory, physicalImageId);
File.WriteAllBytes(fileName, stream.GetBuffer().AsSpan(0, (int)stream.Length));
// Assume that if a file exists, it is already correct. We want to avoid wearing the disk if we don't need to.
if (!File.Exists(fileName))
{
File.WriteAllBytes(fileName, stream.GetBuffer().AsSpan(0, (int)stream.Length));
}
return (physicalImageId, targetFormat, GetImageFile(physicalImageId));
}
}
Expand Down

0 comments on commit ce9e004

Please sign in to comment.