mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Added a tooltip to inform user that format and collection filter selections do not only show for the selected library. * Refactored a lot of code around when we update chapter cover images. Applied an optimization for when we re-calculate volume/series covers, such that it only occurs when the first chapter's image updates. * Updated code to ensure only lastmodified gets refreshed in metadata since it always follows a scan * Optimized how metadata is populated on the series. Instead of re-reading the comicInfos, instead I read the data from the underlying chapter entities. This reduces N additional reads AND enables the ability in the future to show/edit chapter level metadata. * Spelling mistake * Fixed a concurency issue by not selecting Genres from DB. Added a test for long paths. * Fixed a bug in filter where collection tag wasn't populating on load * Cleaned up the logic for changelog to better compare against the installed verison. For nightly users, show the last stable as installed. * Removed some demo code * SplitQuery to allow loading tags much faster for series metadata load.
74 lines
2.7 KiB
C#
74 lines
2.7 KiB
C#
using System;
|
|
using API.Entities;
|
|
using API.Entities.Interfaces;
|
|
using API.Services;
|
|
|
|
namespace API.Helpers;
|
|
|
|
public interface ICacheHelper
|
|
{
|
|
bool ShouldUpdateCoverImage(string coverPath, MangaFile firstFile, DateTime chapterCreated,
|
|
bool forceUpdate = false,
|
|
bool isCoverLocked = false);
|
|
|
|
bool CoverImageExists(string path);
|
|
|
|
bool HasFileNotChangedSinceCreationOrLastScan(IEntityDate chapter, bool forceUpdate, MangaFile firstFile);
|
|
|
|
}
|
|
|
|
public class CacheHelper : ICacheHelper
|
|
{
|
|
private readonly IFileService _fileService;
|
|
|
|
public CacheHelper(IFileService fileService)
|
|
{
|
|
_fileService = fileService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether an entity should regenerate cover image.
|
|
/// </summary>
|
|
/// <remarks>If a cover image is locked but the underlying file has been deleted, this will allow regenerating. </remarks>
|
|
/// <param name="coverPath">This should just be the filename, no path information</param>
|
|
/// <param name="firstFile"></param>
|
|
/// <param name="forceUpdate">If the user has told us to force the refresh</param>
|
|
/// <param name="isCoverLocked">If cover has been locked by user. This will force false</param>
|
|
/// <returns></returns>
|
|
public bool ShouldUpdateCoverImage(string coverPath, MangaFile firstFile, DateTime chapterCreated, bool forceUpdate = false,
|
|
bool isCoverLocked = false)
|
|
{
|
|
|
|
var fileExists = !string.IsNullOrEmpty(coverPath) && _fileService.Exists(coverPath);
|
|
if (isCoverLocked && fileExists) return false;
|
|
if (forceUpdate) return true;
|
|
if (firstFile == null) return true;
|
|
return (_fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified)) || !fileExists;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Has the file been modified since last scan or is user forcing an update
|
|
/// </summary>
|
|
/// <param name="chapter"></param>
|
|
/// <param name="forceUpdate"></param>
|
|
/// <param name="firstFile"></param>
|
|
/// <returns></returns>
|
|
public bool HasFileNotChangedSinceCreationOrLastScan(IEntityDate chapter, bool forceUpdate, MangaFile firstFile)
|
|
{
|
|
return firstFile != null &&
|
|
(!forceUpdate &&
|
|
!(_fileService.HasFileBeenModifiedSince(firstFile.FilePath, chapter.Created)
|
|
|| _fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines if a given coverImage path exists
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
public bool CoverImageExists(string path)
|
|
{
|
|
return !string.IsNullOrEmpty(path) && _fileService.Exists(path);
|
|
}
|
|
}
|