perf(komga): only rescan library on update when relevant

This commit is contained in:
Gauthier Roebroeck 2023-09-20 18:15:11 +08:00
parent c6c7c89a84
commit b48c113bb3

View file

@ -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<Library>) {
if (!Files.exists(library.path))
throw FileNotFoundException("Library root folder does not exist: ${library.root}")