mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 04:22:28 +02:00
parent
594194fafd
commit
4e055f037a
2 changed files with 44 additions and 3 deletions
|
|
@ -206,11 +206,11 @@ class BookDtoDao(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findAllDuplicates(userId: String, pageable: Pageable): Page<BookDto> {
|
override fun findAllDuplicates(userId: String, pageable: Pageable): Page<BookDto> {
|
||||||
val hashes = dsl.select(b.FILE_HASH, DSL.count(b.FILE_HASH))
|
val hashes = dsl.select(b.FILE_HASH, DSL.count(b.ID))
|
||||||
.from(b)
|
.from(b)
|
||||||
.where(b.FILE_HASH.ne(""))
|
.where(b.FILE_HASH.ne(""))
|
||||||
.groupBy(b.FILE_HASH)
|
.groupBy(b.FILE_HASH, b.FILE_SIZE)
|
||||||
.having(DSL.count(b.FILE_HASH).gt(1))
|
.having(DSL.count(b.ID).gt(1))
|
||||||
.fetch()
|
.fetch()
|
||||||
.associate { it.value1() to it.value2() }
|
.associate { it.value1() to it.value2() }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import org.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.data.domain.PageRequest
|
import org.springframework.data.domain.PageRequest
|
||||||
|
import org.springframework.data.domain.Pageable
|
||||||
import org.springframework.data.domain.Sort
|
import org.springframework.data.domain.Sort
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
@ -700,4 +701,44 @@ class BookDtoDaoTest(
|
||||||
assertThat(found).hasSize(1)
|
assertThat(found).hasSize(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class Duplicates {
|
||||||
|
@Test
|
||||||
|
fun `given books with same hash and size when searching then results are returned`() {
|
||||||
|
// given
|
||||||
|
seriesLifecycle.addBooks(
|
||||||
|
series,
|
||||||
|
listOf(
|
||||||
|
makeBook("Book 1", seriesId = series.id, libraryId = library.id).copy(fileHash = "hashed", fileSize = 10),
|
||||||
|
makeBook("Book 2", seriesId = series.id, libraryId = library.id).copy(fileHash = "hashed", fileSize = 10),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
// when
|
||||||
|
val found = bookDtoDao.findAllDuplicates(user.id, Pageable.unpaged(),).content
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(found).hasSize(2)
|
||||||
|
assertThat(found.map { it.name }).containsExactlyInAnyOrder("Book 1", "Book 2")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given books with same hash but different size when searching then no results are returned`() {
|
||||||
|
// given
|
||||||
|
seriesLifecycle.addBooks(
|
||||||
|
series,
|
||||||
|
listOf(
|
||||||
|
makeBook("Book 1", seriesId = series.id, libraryId = library.id).copy(fileHash = "hashed", fileSize = 10),
|
||||||
|
makeBook("Book 2", seriesId = series.id, libraryId = library.id).copy(fileHash = "hashed", fileSize = 12),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
// when
|
||||||
|
val found = bookDtoDao.findAllDuplicates(user.id, Pageable.unpaged(),).content
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(found).isEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue