mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
refactor(benchmark): replace deprecated methods
This commit is contained in:
parent
8a07a7224c
commit
9046a61fc6
3 changed files with 55 additions and 21 deletions
|
|
@ -1,5 +1,9 @@
|
|||
package org.gotson.komga.benchmark.rest
|
||||
|
||||
import org.gotson.komga.domain.model.BookSearch
|
||||
import org.gotson.komga.domain.model.SearchCondition
|
||||
import org.gotson.komga.domain.model.SearchOperator
|
||||
import org.gotson.komga.domain.model.SeriesSearch
|
||||
import org.openjdk.jmh.annotations.Benchmark
|
||||
import org.openjdk.jmh.annotations.Level
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit
|
||||
|
|
@ -25,7 +29,7 @@ class BrowseBenchmark : AbstractRestBenchmark() {
|
|||
// find series with most books
|
||||
biggestSeriesId =
|
||||
seriesController
|
||||
.getSeriesDeprecated(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))))
|
||||
.getSeries(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))), search = SeriesSearch())
|
||||
.content
|
||||
.first()
|
||||
.id
|
||||
|
|
@ -33,11 +37,11 @@ class BrowseBenchmark : AbstractRestBenchmark() {
|
|||
|
||||
@Benchmark
|
||||
fun browseSeries() {
|
||||
seriesController.getSeriesDeprecated(principal, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.titleSort"))))
|
||||
seriesController.getSeries(principal, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.titleSort"))), search = SeriesSearch())
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun browseSeriesBooks() {
|
||||
seriesController.getBooksBySeriesId(principal, biggestSeriesId, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.numberSort"))))
|
||||
bookController.getBooks(principal, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.numberSort"))), search = BookSearch(SearchCondition.SeriesId(SearchOperator.Is(biggestSeriesId))))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,12 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.gotson.komga.domain.model.BookSearch
|
||||
import org.gotson.komga.domain.model.Media
|
||||
import org.gotson.komga.domain.model.ReadStatus
|
||||
import org.gotson.komga.domain.model.SearchCondition
|
||||
import org.gotson.komga.domain.model.SearchOperator
|
||||
import org.gotson.komga.domain.model.SeriesSearch
|
||||
import org.gotson.komga.interfaces.api.rest.dto.ReadProgressUpdateDto
|
||||
import org.openjdk.jmh.annotations.Benchmark
|
||||
import org.openjdk.jmh.annotations.Level
|
||||
|
|
@ -14,13 +18,14 @@ import org.openjdk.jmh.annotations.Setup
|
|||
import org.springframework.data.domain.PageRequest
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.data.domain.Sort
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneOffset
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
class DashboardBenchmark : AbstractRestBenchmark() {
|
||||
companion object {
|
||||
lateinit var bookLatestReleaseDate: LocalDate
|
||||
lateinit var bookLatestReleaseDate: ZonedDateTime
|
||||
}
|
||||
|
||||
@Setup(Level.Trial)
|
||||
|
|
@ -28,9 +33,9 @@ class DashboardBenchmark : AbstractRestBenchmark() {
|
|||
super.prepareData()
|
||||
|
||||
// mark some books in progress
|
||||
bookController.getAllBooksDeprecated(principal, readStatus = listOf(ReadStatus.IN_PROGRESS), page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).let { page ->
|
||||
bookController.getBooks(principal, page = Pageable.ofSize(DEFAULT_PAGE_SIZE), search = BookSearch(SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.IN_PROGRESS)))).let { page ->
|
||||
if (page.totalElements < DEFAULT_PAGE_SIZE) {
|
||||
bookController.getAllBooksDeprecated(principal, readStatus = listOf(ReadStatus.UNREAD), page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).content.forEach { book ->
|
||||
bookController.getBooks(principal, page = Pageable.ofSize(DEFAULT_PAGE_SIZE), search = BookSearch(SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.UNREAD)))).content.forEach { book ->
|
||||
bookController.markBookReadProgress(book.id, ReadProgressUpdateDto(2, false), principal)
|
||||
}
|
||||
}
|
||||
|
|
@ -39,20 +44,33 @@ class DashboardBenchmark : AbstractRestBenchmark() {
|
|||
// mark some books read for on deck
|
||||
bookController.getBooksOnDeck(principal, page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).let { page ->
|
||||
if (page.totalElements < DEFAULT_PAGE_SIZE) {
|
||||
seriesController.getSeriesDeprecated(principal, readStatus = listOf(ReadStatus.UNREAD), oneshot = false, page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).content.forEach { series ->
|
||||
val book = seriesController.getBooksBySeriesId(principal, series.id, page = Pageable.ofSize(1)).content.first()
|
||||
bookController.markBookReadProgress(book.id, ReadProgressUpdateDto(null, true), principal)
|
||||
}
|
||||
seriesController
|
||||
.getSeries(
|
||||
principal,
|
||||
page = Pageable.ofSize(DEFAULT_PAGE_SIZE),
|
||||
search =
|
||||
SeriesSearch(
|
||||
SearchCondition.AllOfSeries(
|
||||
SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.UNREAD)),
|
||||
SearchCondition.OneShot(SearchOperator.IsFalse),
|
||||
),
|
||||
),
|
||||
).content
|
||||
.forEach { series ->
|
||||
val book = bookController.getBooks(principal, page = Pageable.ofSize(1), search = BookSearch(SearchCondition.SeriesId(SearchOperator.Is(series.id)))).content.first()
|
||||
bookController.markBookReadProgress(book.id, ReadProgressUpdateDto(null, true), principal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve most recent book release date
|
||||
bookLatestReleaseDate = bookController
|
||||
.getAllBooksDeprecated(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("metadata.releaseDate"))))
|
||||
.getBooks(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("metadata.releaseDate"))), search = BookSearch())
|
||||
.content
|
||||
.firstOrNull()
|
||||
?.metadata
|
||||
?.releaseDate ?: LocalDate.now()
|
||||
?.releaseDate
|
||||
?.atStartOfDay(ZoneOffset.UTC) ?: ZonedDateTime.now()
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
|
|
@ -73,7 +91,7 @@ class DashboardBenchmark : AbstractRestBenchmark() {
|
|||
|
||||
@Benchmark
|
||||
fun getBooksInProgress() {
|
||||
bookController.getAllBooksDeprecated(principal, readStatus = listOf(ReadStatus.IN_PROGRESS), page = pageableBooksInProgress)
|
||||
bookController.getBooks(principal, page = pageableBooksInProgress, search = BookSearch(SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.IN_PROGRESS))))
|
||||
}
|
||||
|
||||
val pageableBooksOnDeck = Pageable.ofSize(DEFAULT_PAGE_SIZE)
|
||||
|
|
@ -87,14 +105,14 @@ class DashboardBenchmark : AbstractRestBenchmark() {
|
|||
|
||||
@Benchmark
|
||||
fun getBooksLatest() {
|
||||
bookController.getAllBooksDeprecated(principal, page = pageableBooksLatest)
|
||||
bookController.getBooks(principal, page = pageableBooksLatest, search = BookSearch())
|
||||
}
|
||||
|
||||
val pageableBooksRecentlyReleased = PageRequest.of(0, DEFAULT_PAGE_SIZE, Sort.by(Sort.Order.desc("metadata.releaseDate")))
|
||||
|
||||
@Benchmark
|
||||
fun getBooksRecentlyReleased() {
|
||||
bookController.getAllBooksDeprecated(principal, releasedAfter = bookLatestReleaseDate.minusMonths(1), page = pageableBooksRecentlyReleased)
|
||||
fun getBooksRecentlyReleased() { // releasedAfter = bookLatestReleaseDate.minusMonths(1)
|
||||
bookController.getBooks(principal, page = pageableBooksRecentlyReleased, search = BookSearch(SearchCondition.ReleaseDate(SearchOperator.After(bookLatestReleaseDate.minusMonths(1)))))
|
||||
}
|
||||
|
||||
val pageableSeriesNew = Pageable.ofSize(DEFAULT_PAGE_SIZE)
|
||||
|
|
@ -115,6 +133,16 @@ class DashboardBenchmark : AbstractRestBenchmark() {
|
|||
|
||||
@Benchmark
|
||||
fun getBooksToCheck() {
|
||||
bookController.getAllBooksDeprecated(principal, mediaStatus = listOf(Media.Status.ERROR, Media.Status.UNSUPPORTED), page = pageableBooksToCheck)
|
||||
bookController.getBooks(
|
||||
principal,
|
||||
page = pageableBooksToCheck,
|
||||
search =
|
||||
BookSearch(
|
||||
SearchCondition.AnyOfBook(
|
||||
SearchCondition.MediaStatus(SearchOperator.Is(Media.Status.ERROR)),
|
||||
SearchCondition.MediaStatus(SearchOperator.Is(Media.Status.UNSUPPORTED)),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.gotson.komga.benchmark.rest
|
||||
|
||||
import org.gotson.komga.domain.model.BookSearch
|
||||
import org.gotson.komga.domain.model.SeriesSearch
|
||||
import org.openjdk.jmh.annotations.Benchmark
|
||||
import org.openjdk.jmh.annotations.Level
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit
|
||||
|
|
@ -24,7 +26,7 @@ class UnsortedBenchmark : AbstractRestBenchmark() {
|
|||
// find series with most books
|
||||
biggestSeriesId =
|
||||
seriesController
|
||||
.getSeriesDeprecated(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))))
|
||||
.getSeries(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))), search = SeriesSearch())
|
||||
.content
|
||||
.first()
|
||||
.id
|
||||
|
|
@ -32,11 +34,11 @@ class UnsortedBenchmark : AbstractRestBenchmark() {
|
|||
|
||||
@Benchmark
|
||||
fun getAllSeries() {
|
||||
seriesController.getSeriesDeprecated(principal, page = Pageable.ofSize(pageSize))
|
||||
seriesController.getSeries(principal, page = Pageable.ofSize(pageSize), search = SeriesSearch())
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun getAllBooks() {
|
||||
bookController.getAllBooksDeprecated(principal, page = Pageable.ofSize(pageSize))
|
||||
bookController.getBooks(principal, page = Pageable.ofSize(pageSize), search = BookSearch())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue