From 667d1d2a4d64b3093069ad1e3bb6b00b4a0a1045 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Wed, 31 Mar 2021 12:53:53 -0500 Subject: [PATCH] Don't go to archive file if it hasn't updated since last scan (#135) * Skip archive work unless the file has actually changed since last scan. --- API/Extensions/FileInfoExtensions.cs | 5 +++++ API/Services/MetadataService.cs | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/API/Extensions/FileInfoExtensions.cs b/API/Extensions/FileInfoExtensions.cs index eda352fc8..d96b06de6 100644 --- a/API/Extensions/FileInfoExtensions.cs +++ b/API/Extensions/FileInfoExtensions.cs @@ -9,5 +9,10 @@ namespace API.Extensions { return comparison.Equals(fileInfo.LastWriteTime); } + + public static bool IsLastWriteOlder(this FileInfo fileInfo, DateTime comparison) + { + return comparison > fileInfo.LastWriteTime; + } } } \ No newline at end of file diff --git a/API/Services/MetadataService.cs b/API/Services/MetadataService.cs index 12d39cbf3..405e4c7e1 100644 --- a/API/Services/MetadataService.cs +++ b/API/Services/MetadataService.cs @@ -32,19 +32,17 @@ namespace API.Services public void UpdateMetadata(Chapter chapter, bool forceUpdate) { - // TODO: Figure a way to skip UpdateMetadata: && new FileInfo(chapter.Files.FirstOrDefault()?.FilePath).LastWriteTime < - if (chapter != null && ShouldFindCoverImage(chapter.CoverImage, forceUpdate)) + var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault(); + if (ShouldFindCoverImage(chapter.CoverImage, forceUpdate) && firstFile != null && new FileInfo(firstFile.FilePath).IsLastWriteOlder(firstFile.LastModified)) { chapter.Files ??= new List(); - var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault(); - if (firstFile != null) chapter.CoverImage = _archiveService.GetCoverImage(firstFile.FilePath, true); + chapter.CoverImage = _archiveService.GetCoverImage(firstFile.FilePath, true); } } public void UpdateMetadata(Volume volume, bool forceUpdate) { - // TODO: Figure a way to skip UpdateMetadata: if (volume != null && ShouldFindCoverImage(volume.CoverImage, forceUpdate)) { // TODO: Create a custom sorter for Chapters so it's consistent across the application @@ -55,7 +53,7 @@ namespace API.Services // Skip calculating Cover Image (I/O) if the chapter already has it set if (firstChapter == null || ShouldFindCoverImage(firstChapter.CoverImage)) { - if (firstFile != null && !new FileInfo(firstFile.FilePath).DoesLastWriteMatch(firstFile.LastModified)) + if (firstFile != null && !new FileInfo(firstFile.FilePath).IsLastWriteOlder(firstFile.LastModified)) { volume.CoverImage = _archiveService.GetCoverImage(firstFile.FilePath, true); }