From b48c113bb3ac1f03696a2c9eb6a6a5bb23682e96 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Wed, 20 Sep 2023 18:15:11 +0800 Subject: [PATCH] perf(komga): only rescan library on update when relevant --- .../gotson/komga/domain/service/LibraryLifecycle.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryLifecycle.kt b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryLifecycle.kt index a24a0d72..ef17202b 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryLifecycle.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryLifecycle.kt @@ -64,11 +64,22 @@ class LibraryLifecycle( if (current.scanInterval != toUpdate.scanInterval) libraryScanScheduler.scheduleScan(toUpdate) - taskEmitter.scanLibrary(toUpdate.id) + if (checkLibraryShouldRescan(current, toUpdate)) + taskEmitter.scanLibrary(toUpdate.id) eventPublisher.publishEvent(DomainEvent.LibraryUpdated(toUpdate)) } + private fun checkLibraryShouldRescan(existing: Library, updated: Library): Boolean { + if (existing.root != updated.root) return true + if (existing.oneshotsDirectory != updated.oneshotsDirectory) return true + if (existing.scanCbx != updated.scanCbx) return true + if (existing.scanPdf != updated.scanPdf) return true + if (existing.scanEpub != updated.scanEpub) return true + if (existing.scanForceModifiedTime != updated.scanForceModifiedTime) return true + return false + } + private fun checkLibraryValidity(library: Library, existing: Collection) { if (!Files.exists(library.path)) throw FileNotFoundException("Library root folder does not exist: ${library.root}")