Skip to content

Commit 9046a61

Browse files
committed
refactor(benchmark): replace deprecated methods
1 parent 8a07a72 commit 9046a61

File tree

3 files changed

+55
-21
lines changed

3 files changed

+55
-21
lines changed

komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/BrowseBenchmark.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.gotson.komga.benchmark.rest
22

3+
import org.gotson.komga.domain.model.BookSearch
4+
import org.gotson.komga.domain.model.SearchCondition
5+
import org.gotson.komga.domain.model.SearchOperator
6+
import org.gotson.komga.domain.model.SeriesSearch
37
import org.openjdk.jmh.annotations.Benchmark
48
import org.openjdk.jmh.annotations.Level
59
import org.openjdk.jmh.annotations.OutputTimeUnit
@@ -25,19 +29,19 @@ class BrowseBenchmark : AbstractRestBenchmark() {
2529
// find series with most books
2630
biggestSeriesId =
2731
seriesController
28-
.getSeriesDeprecated(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))))
32+
.getSeries(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))), search = SeriesSearch())
2933
.content
3034
.first()
3135
.id
3236
}
3337

3438
@Benchmark
3539
fun browseSeries() {
36-
seriesController.getSeriesDeprecated(principal, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.titleSort"))))
40+
seriesController.getSeries(principal, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.titleSort"))), search = SeriesSearch())
3741
}
3842

3943
@Benchmark
4044
fun browseSeriesBooks() {
41-
seriesController.getBooksBySeriesId(principal, biggestSeriesId, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.numberSort"))))
45+
bookController.getBooks(principal, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.numberSort"))), search = BookSearch(SearchCondition.SeriesId(SearchOperator.Is(biggestSeriesId))))
4246
}
4347
}

komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/DashboardBenchmark.kt

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import kotlinx.coroutines.Dispatchers
44
import kotlinx.coroutines.launch
55
import kotlinx.coroutines.runBlocking
66
import kotlinx.coroutines.withContext
7+
import org.gotson.komga.domain.model.BookSearch
78
import org.gotson.komga.domain.model.Media
89
import org.gotson.komga.domain.model.ReadStatus
10+
import org.gotson.komga.domain.model.SearchCondition
11+
import org.gotson.komga.domain.model.SearchOperator
12+
import org.gotson.komga.domain.model.SeriesSearch
913
import org.gotson.komga.interfaces.api.rest.dto.ReadProgressUpdateDto
1014
import org.openjdk.jmh.annotations.Benchmark
1115
import org.openjdk.jmh.annotations.Level
@@ -14,23 +18,24 @@ import org.openjdk.jmh.annotations.Setup
1418
import org.springframework.data.domain.PageRequest
1519
import org.springframework.data.domain.Pageable
1620
import org.springframework.data.domain.Sort
17-
import java.time.LocalDate
21+
import java.time.ZoneOffset
22+
import java.time.ZonedDateTime
1823
import java.util.concurrent.TimeUnit
1924

2025
@OutputTimeUnit(TimeUnit.MILLISECONDS)
2126
class DashboardBenchmark : AbstractRestBenchmark() {
2227
companion object {
23-
lateinit var bookLatestReleaseDate: LocalDate
28+
lateinit var bookLatestReleaseDate: ZonedDateTime
2429
}
2530

2631
@Setup(Level.Trial)
2732
override fun prepareData() {
2833
super.prepareData()
2934

3035
// mark some books in progress
31-
bookController.getAllBooksDeprecated(principal, readStatus = listOf(ReadStatus.IN_PROGRESS), page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).let { page ->
36+
bookController.getBooks(principal, page = Pageable.ofSize(DEFAULT_PAGE_SIZE), search = BookSearch(SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.IN_PROGRESS)))).let { page ->
3237
if (page.totalElements < DEFAULT_PAGE_SIZE) {
33-
bookController.getAllBooksDeprecated(principal, readStatus = listOf(ReadStatus.UNREAD), page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).content.forEach { book ->
38+
bookController.getBooks(principal, page = Pageable.ofSize(DEFAULT_PAGE_SIZE), search = BookSearch(SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.UNREAD)))).content.forEach { book ->
3439
bookController.markBookReadProgress(book.id, ReadProgressUpdateDto(2, false), principal)
3540
}
3641
}
@@ -39,20 +44,33 @@ class DashboardBenchmark : AbstractRestBenchmark() {
3944
// mark some books read for on deck
4045
bookController.getBooksOnDeck(principal, page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).let { page ->
4146
if (page.totalElements < DEFAULT_PAGE_SIZE) {
42-
seriesController.getSeriesDeprecated(principal, readStatus = listOf(ReadStatus.UNREAD), oneshot = false, page = Pageable.ofSize(DEFAULT_PAGE_SIZE)).content.forEach { series ->
43-
val book = seriesController.getBooksBySeriesId(principal, series.id, page = Pageable.ofSize(1)).content.first()
44-
bookController.markBookReadProgress(book.id, ReadProgressUpdateDto(null, true), principal)
45-
}
47+
seriesController
48+
.getSeries(
49+
principal,
50+
page = Pageable.ofSize(DEFAULT_PAGE_SIZE),
51+
search =
52+
SeriesSearch(
53+
SearchCondition.AllOfSeries(
54+
SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.UNREAD)),
55+
SearchCondition.OneShot(SearchOperator.IsFalse),
56+
),
57+
),
58+
).content
59+
.forEach { series ->
60+
val book = bookController.getBooks(principal, page = Pageable.ofSize(1), search = BookSearch(SearchCondition.SeriesId(SearchOperator.Is(series.id)))).content.first()
61+
bookController.markBookReadProgress(book.id, ReadProgressUpdateDto(null, true), principal)
62+
}
4663
}
4764
}
4865

4966
// retrieve most recent book release date
5067
bookLatestReleaseDate = bookController
51-
.getAllBooksDeprecated(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("metadata.releaseDate"))))
68+
.getBooks(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("metadata.releaseDate"))), search = BookSearch())
5269
.content
5370
.firstOrNull()
5471
?.metadata
55-
?.releaseDate ?: LocalDate.now()
72+
?.releaseDate
73+
?.atStartOfDay(ZoneOffset.UTC) ?: ZonedDateTime.now()
5674
}
5775

5876
@Benchmark
@@ -73,7 +91,7 @@ class DashboardBenchmark : AbstractRestBenchmark() {
7391

7492
@Benchmark
7593
fun getBooksInProgress() {
76-
bookController.getAllBooksDeprecated(principal, readStatus = listOf(ReadStatus.IN_PROGRESS), page = pageableBooksInProgress)
94+
bookController.getBooks(principal, page = pageableBooksInProgress, search = BookSearch(SearchCondition.ReadStatus(SearchOperator.Is(ReadStatus.IN_PROGRESS))))
7795
}
7896

7997
val pageableBooksOnDeck = Pageable.ofSize(DEFAULT_PAGE_SIZE)
@@ -87,14 +105,14 @@ class DashboardBenchmark : AbstractRestBenchmark() {
87105

88106
@Benchmark
89107
fun getBooksLatest() {
90-
bookController.getAllBooksDeprecated(principal, page = pageableBooksLatest)
108+
bookController.getBooks(principal, page = pageableBooksLatest, search = BookSearch())
91109
}
92110

93111
val pageableBooksRecentlyReleased = PageRequest.of(0, DEFAULT_PAGE_SIZE, Sort.by(Sort.Order.desc("metadata.releaseDate")))
94112

95113
@Benchmark
96-
fun getBooksRecentlyReleased() {
97-
bookController.getAllBooksDeprecated(principal, releasedAfter = bookLatestReleaseDate.minusMonths(1), page = pageableBooksRecentlyReleased)
114+
fun getBooksRecentlyReleased() { // releasedAfter = bookLatestReleaseDate.minusMonths(1)
115+
bookController.getBooks(principal, page = pageableBooksRecentlyReleased, search = BookSearch(SearchCondition.ReleaseDate(SearchOperator.After(bookLatestReleaseDate.minusMonths(1)))))
98116
}
99117

100118
val pageableSeriesNew = Pageable.ofSize(DEFAULT_PAGE_SIZE)
@@ -115,6 +133,16 @@ class DashboardBenchmark : AbstractRestBenchmark() {
115133

116134
@Benchmark
117135
fun getBooksToCheck() {
118-
bookController.getAllBooksDeprecated(principal, mediaStatus = listOf(Media.Status.ERROR, Media.Status.UNSUPPORTED), page = pageableBooksToCheck)
136+
bookController.getBooks(
137+
principal,
138+
page = pageableBooksToCheck,
139+
search =
140+
BookSearch(
141+
SearchCondition.AnyOfBook(
142+
SearchCondition.MediaStatus(SearchOperator.Is(Media.Status.ERROR)),
143+
SearchCondition.MediaStatus(SearchOperator.Is(Media.Status.UNSUPPORTED)),
144+
),
145+
),
146+
)
119147
}
120148
}

komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/UnsortedBenchmark.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.gotson.komga.benchmark.rest
22

3+
import org.gotson.komga.domain.model.BookSearch
4+
import org.gotson.komga.domain.model.SeriesSearch
35
import org.openjdk.jmh.annotations.Benchmark
46
import org.openjdk.jmh.annotations.Level
57
import org.openjdk.jmh.annotations.OutputTimeUnit
@@ -24,19 +26,19 @@ class UnsortedBenchmark : AbstractRestBenchmark() {
2426
// find series with most books
2527
biggestSeriesId =
2628
seriesController
27-
.getSeriesDeprecated(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))))
29+
.getSeries(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount"))), search = SeriesSearch())
2830
.content
2931
.first()
3032
.id
3133
}
3234

3335
@Benchmark
3436
fun getAllSeries() {
35-
seriesController.getSeriesDeprecated(principal, page = Pageable.ofSize(pageSize))
37+
seriesController.getSeries(principal, page = Pageable.ofSize(pageSize), search = SeriesSearch())
3638
}
3739

3840
@Benchmark
3941
fun getAllBooks() {
40-
bookController.getAllBooksDeprecated(principal, page = Pageable.ofSize(pageSize))
42+
bookController.getBooks(principal, page = Pageable.ofSize(pageSize), search = BookSearch())
4143
}
4244
}

0 commit comments

Comments
 (0)