Optimised searching for multiple tags at once
This commit is contained in:
parent
90bb712bc3
commit
f97358aeb4
@ -56,7 +56,7 @@ class ImageController
|
||||
"" -> imageRepository.findAll(page)
|
||||
else -> {
|
||||
val distinctTags = tags.split(" ").distinct()
|
||||
val tagData = distinctTags.mapNotNull { tagRepository.findByTagIs(it) } // Try to get actual tag objects
|
||||
val tagData = tagRepository.findAllByTagIn(distinctTags) // Try to get actual tag objects
|
||||
when {
|
||||
tagData.isEmpty() -> null // No tags existed with the specified search terms
|
||||
tagData.size != distinctTags.size -> null // Error if an invalid tag was supplied
|
||||
|
@ -13,10 +13,9 @@ interface UserRepository : CrudRepository<User, Long> {
|
||||
interface RoleRepository : CrudRepository<Role, Long>
|
||||
|
||||
interface ImageRepository : JpaRepository<Image, Long> {
|
||||
//@Query("select i from Image i join i.tags t where t in ?1 group by i.id having count(i.id) = ?2")
|
||||
@Suppress("SqlResolve")
|
||||
@Query(
|
||||
value = "select * from booru.image i where i.id in (select image_id from booru.tag_image ti where ti.tag_id in ?1 group by ti.image_id having count(ti.image_id) = ?2) order by i.id",
|
||||
value = "WITH X AS (SELECT IMAGE_ID FROM BOORU.TAG_IMAGE TI WHERE TI.TAG_ID in ?1 GROUP BY TI.IMAGE_ID HAVING COUNT(TI.IMAGE_ID) = ?2) SELECT I.* FROM BOORU.IMAGE I RIGHT JOIN X ON I.ID = X.IMAGE_ID ORDER BY I.ID",
|
||||
nativeQuery = true
|
||||
)
|
||||
fun findByTagsOrderById(tagIDs: List<Tag>, tagCount: Long, pageable: Pageable): Page<Image>
|
||||
@ -26,4 +25,5 @@ interface ImageRepository : JpaRepository<Image, Long> {
|
||||
|
||||
interface TagRepository : CrudRepository<Tag, Long> {
|
||||
fun findByTagIs(tag: String): Tag?
|
||||
fun findAllByTagIn(tags: List<String>): List<Tag>
|
||||
}
|
Loading…
Reference in New Issue
Block a user