diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/BookRepository.kt b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/BookRepository.kt index c9ef439b5..370277ad5 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/BookRepository.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/BookRepository.kt @@ -9,7 +9,7 @@ import java.net.URL interface BookRepository { fun findByIdOrNull(bookId: String): Book? - fun findByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Book? + fun findNotDeletedByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Book? fun findAll(): Collection fun findAllBySeriesId(seriesId: String): Collection diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/SeriesRepository.kt b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/SeriesRepository.kt index 75b55994a..9fd8f5277 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/SeriesRepository.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/SeriesRepository.kt @@ -6,7 +6,7 @@ import java.net.URL interface SeriesRepository { fun findByIdOrNull(seriesId: String): Series? - fun findByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Series? + fun findNotDeletedByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Series? fun findAll(): Collection fun findAllByLibraryId(libraryId: String): Collection diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt index 7f372dc6a..a14a4bb99 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/service/LibraryContentLifecycle.kt @@ -118,7 +118,7 @@ class LibraryContentLifecycle( val seriesUrlWithDeletedBooks = seriesToSortAndRefresh.map { it.url } scannedSeries.forEach { (newSeries, newBooks) -> - val existingSeries = seriesRepository.findByLibraryIdAndUrlOrNull(library.id, newSeries.url) + val existingSeries = seriesRepository.findNotDeletedByLibraryIdAndUrlOrNull(library.id, newSeries.url) // if series does not exist, save it if (existingSeries == null) { @@ -186,7 +186,7 @@ class LibraryContentLifecycle( if (existingSidecar == null || existingSidecar.lastModifiedTime.notEquals(newSidecar.lastModifiedTime)) { when (newSidecar.source) { Sidecar.Source.SERIES -> - seriesRepository.findByLibraryIdAndUrlOrNull(library.id, newSidecar.parentUrl)?.let { series -> + seriesRepository.findNotDeletedByLibraryIdAndUrlOrNull(library.id, newSidecar.parentUrl)?.let { series -> logger.info { "Sidecar changed on disk (${newSidecar.url}, refresh Series for ${newSidecar.type}: $series" } when (newSidecar.type) { Sidecar.Type.ARTWORK -> taskReceiver.refreshSeriesLocalArtwork(series.id) @@ -194,7 +194,7 @@ class LibraryContentLifecycle( } } Sidecar.Source.BOOK -> - bookRepository.findByLibraryIdAndUrlOrNull(library.id, newSidecar.parentUrl)?.let { book -> + bookRepository.findNotDeletedByLibraryIdAndUrlOrNull(library.id, newSidecar.parentUrl)?.let { book -> logger.info { "Sidecar changed on disk (${newSidecar.url}, refresh Book for ${newSidecar.type}: $book" } when (newSidecar.type) { Sidecar.Type.ARTWORK -> taskReceiver.refreshBookLocalArtwork(book.id) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDao.kt index 3b7067f4f..26a4ad9ee 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDao.kt @@ -39,9 +39,10 @@ class BookDao( override fun findByIdOrNull(bookId: String): Book? = findByIdOrNull(dsl, bookId) - override fun findByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Book? = + override fun findNotDeletedByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Book? = dsl.selectFrom(b) .where(b.LIBRARY_ID.eq(libraryId).and(b.URL.eq(url.toString()))) + .and(b.DELETED_DATE.isNull) .fetchOneInto(b) ?.toDomain() diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt index 55d03bd34..dc957e997 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt @@ -64,9 +64,10 @@ class SeriesDao( .map { it.toDomain() } } - override fun findByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Series? = + override fun findNotDeletedByLibraryIdAndUrlOrNull(libraryId: String, url: URL): Series? = dsl.selectFrom(s) .where(s.LIBRARY_ID.eq(libraryId).and(s.URL.eq(url.toString()))) + .and(s.DELETED_DATE.isNull) .fetchOneInto(s) ?.toDomain() diff --git a/komga/src/test/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDaoTest.kt b/komga/src/test/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDaoTest.kt index 31561d4eb..3497de2c4 100644 --- a/komga/src/test/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDaoTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDaoTest.kt @@ -288,10 +288,10 @@ class SeriesDaoTest( ) seriesDao.insert(series) - val found = seriesDao.findByLibraryIdAndUrlOrNull(library.id, URL("file://series")) - val notFound1 = seriesDao.findByLibraryIdAndUrlOrNull(library.id, URL("file://series2")) - val notFound2 = seriesDao.findByLibraryIdAndUrlOrNull(library.id + 1, URL("file://series")) - val notFound3 = seriesDao.findByLibraryIdAndUrlOrNull(library.id + 1, URL("file://series2")) + val found = seriesDao.findNotDeletedByLibraryIdAndUrlOrNull(library.id, URL("file://series")) + val notFound1 = seriesDao.findNotDeletedByLibraryIdAndUrlOrNull(library.id, URL("file://series2")) + val notFound2 = seriesDao.findNotDeletedByLibraryIdAndUrlOrNull(library.id + 1, URL("file://series")) + val notFound3 = seriesDao.findNotDeletedByLibraryIdAndUrlOrNull(library.id + 1, URL("file://series2")) assertThat(found).isNotNull assertThat(found?.name).isEqualTo("Series")