mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 21:00:16 +02:00
perf: remove subquery
This commit is contained in:
parent
8b5ae64dd5
commit
b162cdeba3
1 changed files with 9 additions and 17 deletions
|
|
@ -111,7 +111,7 @@ class SeriesDtoDao(
|
||||||
selectBase(userId)
|
selectBase(userId)
|
||||||
.where(s.ID.eq(seriesId))
|
.where(s.ID.eq(seriesId))
|
||||||
.groupBy(*groupFields)
|
.groupBy(*groupFields)
|
||||||
.fetchAndMap(userId)
|
.fetchAndMap()
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
|
|
||||||
private fun selectBase(
|
private fun selectBase(
|
||||||
|
|
@ -120,6 +120,9 @@ class SeriesDtoDao(
|
||||||
): SelectOnConditionStep<Record> =
|
): SelectOnConditionStep<Record> =
|
||||||
dsl.selectDistinct(*groupFields)
|
dsl.selectDistinct(*groupFields)
|
||||||
.select(DSL.countDistinct(b.ID).`as`(BOOKS_COUNT))
|
.select(DSL.countDistinct(b.ID).`as`(BOOKS_COUNT))
|
||||||
|
.select(countUnread.`as`(BOOKS_UNREAD_COUNT))
|
||||||
|
.select(countRead.`as`(BOOKS_READ_COUNT))
|
||||||
|
.select(countInProgress.`as`(BOOKS_IN_PROGRESS_COUNT))
|
||||||
.apply { if (joinConditions.selectCollectionNumber) select(cs.NUMBER) }
|
.apply { if (joinConditions.selectCollectionNumber) select(cs.NUMBER) }
|
||||||
.from(s)
|
.from(s)
|
||||||
.leftJoin(b).on(s.ID.eq(b.SERIES_ID))
|
.leftJoin(b).on(s.ID.eq(b.SERIES_ID))
|
||||||
|
|
@ -162,7 +165,7 @@ class SeriesDtoDao(
|
||||||
.having(having)
|
.having(having)
|
||||||
.orderBy(orderBy)
|
.orderBy(orderBy)
|
||||||
.apply { if (pageable.isPaged) limit(pageable.pageSize).offset(pageable.offset) }
|
.apply { if (pageable.isPaged) limit(pageable.pageSize).offset(pageable.offset) }
|
||||||
.fetchAndMap(userId)
|
.fetchAndMap()
|
||||||
|
|
||||||
val pageSort = if (orderBy.size > 1) pageable.sort else Sort.unsorted()
|
val pageSort = if (orderBy.size > 1) pageable.sort else Sort.unsorted()
|
||||||
return PageImpl(
|
return PageImpl(
|
||||||
|
|
@ -175,27 +178,16 @@ class SeriesDtoDao(
|
||||||
|
|
||||||
private fun readProgressCondition(userId: String): Condition = r.USER_ID.eq(userId).or(r.USER_ID.isNull)
|
private fun readProgressCondition(userId: String): Condition = r.USER_ID.eq(userId).or(r.USER_ID.isNull)
|
||||||
|
|
||||||
private fun ResultQuery<Record>.fetchAndMap(userId: String) =
|
private fun ResultQuery<Record>.fetchAndMap() =
|
||||||
fetch()
|
fetch()
|
||||||
.map { rec ->
|
.map { rec ->
|
||||||
val sr = rec.into(s)
|
val sr = rec.into(s)
|
||||||
val dr = rec.into(d)
|
val dr = rec.into(d)
|
||||||
val bmar = rec.into(bma)
|
val bmar = rec.into(bma)
|
||||||
val booksCount = rec.get(BOOKS_COUNT, Int::class.java)
|
val booksCount = rec.get(BOOKS_COUNT, Int::class.java)
|
||||||
|
val booksUnreadCount = rec.get(BOOKS_UNREAD_COUNT, Int::class.java)
|
||||||
val booksCountRecord = dsl
|
val booksReadCount = rec.get(BOOKS_READ_COUNT, Int::class.java)
|
||||||
.select(countUnread.`as`(BOOKS_UNREAD_COUNT))
|
val booksInProgressCount = rec.get(BOOKS_IN_PROGRESS_COUNT, Int::class.java)
|
||||||
.select(countRead.`as`(BOOKS_READ_COUNT))
|
|
||||||
.select(countInProgress.`as`(BOOKS_IN_PROGRESS_COUNT))
|
|
||||||
.from(b)
|
|
||||||
.leftJoin(r).on(b.ID.eq(r.BOOK_ID)).and(readProgressCondition(userId))
|
|
||||||
.where(b.SERIES_ID.eq(sr.id))
|
|
||||||
.fetch()
|
|
||||||
.first()
|
|
||||||
|
|
||||||
val booksUnreadCount = booksCountRecord.get(BOOKS_UNREAD_COUNT, Int::class.java)
|
|
||||||
val booksReadCount = booksCountRecord.get(BOOKS_READ_COUNT, Int::class.java)
|
|
||||||
val booksInProgressCount = booksCountRecord.get(BOOKS_IN_PROGRESS_COUNT, Int::class.java)
|
|
||||||
|
|
||||||
val genres = dsl.select(g.GENRE)
|
val genres = dsl.select(g.GENRE)
|
||||||
.from(g)
|
.from(g)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue