mirror of
https://github.com/gotson/komga.git
synced 2025-12-16 13:33:49 +01:00
perf: don't recompute book hash during scan if filesize is different
This commit is contained in:
parent
1faaf12de4
commit
33cd19ae04
2 changed files with 39 additions and 1 deletions
|
|
@ -147,7 +147,7 @@ class LibraryContentLifecycle(
|
|||
existingBooks.find { it.url == newBook.url && it.deletedDate == null }?.let { existingBook ->
|
||||
logger.debug { "Matched existing book: $existingBook" }
|
||||
if (newBook.fileLastModified.notEquals(existingBook.fileLastModified)) {
|
||||
val hash = if (existingBook.fileHash.isNotBlank()) {
|
||||
val hash = if (existingBook.fileSize == newBook.fileSize && existingBook.fileHash.isNotBlank()) {
|
||||
hasher.computeHash(newBook.path)
|
||||
} else null
|
||||
if (hash == existingBook.fileHash) {
|
||||
|
|
|
|||
|
|
@ -208,6 +208,44 @@ class LibraryContentLifecycleTest(
|
|||
assertThat(media.status).isEqualTo(Media.Status.OUTDATED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given existing series when scanning and updated files have a different size then books are marked outdated`() {
|
||||
// given
|
||||
val library = makeLibrary()
|
||||
libraryRepository.insert(library)
|
||||
|
||||
every { mockScanner.scanRootFolder(any()) }
|
||||
.returnsMany(
|
||||
mapOf(makeSeries(name = "series") to listOf(makeBook("book1").copy(fileSize = 1))).toScanResult(),
|
||||
mapOf(makeSeries(name = "series") to listOf(makeBook("book1").copy(fileSize = 2))).toScanResult(),
|
||||
)
|
||||
libraryContentLifecycle.scanRootFolder(library)
|
||||
|
||||
bookRepository.findAll().first().let { book ->
|
||||
bookRepository.update(book.copy(fileHash = "hashed"))
|
||||
mediaRepository.update(mediaRepository.findById(book.id).copy(status = Media.Status.READY))
|
||||
}
|
||||
|
||||
// when
|
||||
libraryContentLifecycle.scanRootFolder(library)
|
||||
|
||||
// then
|
||||
val allSeries = seriesRepository.findAll()
|
||||
val allBooks = bookRepository.findAll()
|
||||
|
||||
verify(exactly = 2) { mockScanner.scanRootFolder(any()) }
|
||||
verify(exactly = 0) { mockHasher.computeHash(any<Path>()) }
|
||||
|
||||
assertThat(allSeries).hasSize(1)
|
||||
assertThat(allBooks).hasSize(1)
|
||||
val book = allBooks.first()
|
||||
assertThat(book.name).isEqualTo("book1")
|
||||
assertThat(book.lastModifiedDate).isNotEqualTo(book.createdDate)
|
||||
assertThat(book.fileHash).isBlank
|
||||
val media = mediaRepository.findById(book.id)
|
||||
assertThat(media.status).isEqualTo(Media.Status.OUTDATED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given existing series when scanning and updated files have the same hash then books are not marked outdated`() {
|
||||
// given
|
||||
|
|
|
|||
Loading…
Reference in a new issue