mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 23:45:11 +01:00
revamp logic to getAll series to reduce the database load
This commit is contained in:
parent
8db87afd52
commit
66f3d80c9e
1 changed files with 15 additions and 9 deletions
|
|
@ -53,19 +53,25 @@ class SeriesController(
|
|||
)
|
||||
|
||||
return mutableListOf<Specification<Series>>().let { specs ->
|
||||
when {
|
||||
!principal.user.sharedAllLibraries && !libraryIds.isNullOrEmpty() -> {
|
||||
val authorizedLibraryIDs = libraryIds.intersect(principal.user.sharedLibraries.map { it.id })
|
||||
if (authorizedLibraryIDs.isEmpty()) return@let Page.empty<Series>(pageRequest)
|
||||
else specs.add(Series::library.`in`(libraryRepository.findAllById(authorizedLibraryIDs)))
|
||||
}
|
||||
|
||||
!principal.user.sharedAllLibraries -> specs.add(Series::library.`in`(principal.user.sharedLibraries))
|
||||
|
||||
!libraryIds.isNullOrEmpty() -> {
|
||||
val values = libraryRepository.findAllById(libraryIds)
|
||||
specs.add(Series::library.`in`(values))
|
||||
}
|
||||
}
|
||||
|
||||
if (!searchTerm.isNullOrEmpty()) {
|
||||
specs.add(Series::name.likeLower("%$searchTerm%"))
|
||||
}
|
||||
|
||||
if (!principal.user.sharedAllLibraries) {
|
||||
specs.add(Series::library.`in`(principal.user.sharedLibraries))
|
||||
}
|
||||
|
||||
if (!libraryIds.isNullOrEmpty()) {
|
||||
val libraries = libraryRepository.findAllById(libraryIds)
|
||||
specs.add(Series::library.`in`(libraries))
|
||||
}
|
||||
|
||||
if (specs.isNotEmpty()) {
|
||||
seriesRepository.findAll(specs.reduce { acc, spec -> acc.and(spec)!! }, pageRequest)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue