@@ -4,8 +4,12 @@ import kotlinx.coroutines.Dispatchers
4
4
import kotlinx.coroutines.launch
5
5
import kotlinx.coroutines.runBlocking
6
6
import kotlinx.coroutines.withContext
7
+ import org.gotson.komga.domain.model.BookSearch
7
8
import org.gotson.komga.domain.model.Media
8
9
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
9
13
import org.gotson.komga.interfaces.api.rest.dto.ReadProgressUpdateDto
10
14
import org.openjdk.jmh.annotations.Benchmark
11
15
import org.openjdk.jmh.annotations.Level
@@ -14,23 +18,24 @@ import org.openjdk.jmh.annotations.Setup
14
18
import org.springframework.data.domain.PageRequest
15
19
import org.springframework.data.domain.Pageable
16
20
import org.springframework.data.domain.Sort
17
- import java.time.LocalDate
21
+ import java.time.ZoneOffset
22
+ import java.time.ZonedDateTime
18
23
import java.util.concurrent.TimeUnit
19
24
20
25
@OutputTimeUnit(TimeUnit .MILLISECONDS )
21
26
class DashboardBenchmark : AbstractRestBenchmark () {
22
27
companion object {
23
- lateinit var bookLatestReleaseDate: LocalDate
28
+ lateinit var bookLatestReleaseDate: ZonedDateTime
24
29
}
25
30
26
31
@Setup(Level .Trial )
27
32
override fun prepareData () {
28
33
super .prepareData()
29
34
30
35
// 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 ->
32
37
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 ->
34
39
bookController.markBookReadProgress(book.id, ReadProgressUpdateDto (2 , false ), principal)
35
40
}
36
41
}
@@ -39,20 +44,33 @@ class DashboardBenchmark : AbstractRestBenchmark() {
39
44
// mark some books read for on deck
40
45
bookController.getBooksOnDeck(principal, page = Pageable .ofSize(DEFAULT_PAGE_SIZE )).let { page ->
41
46
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
+ }
46
63
}
47
64
}
48
65
49
66
// retrieve most recent book release date
50
67
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 ( ))
52
69
.content
53
70
.firstOrNull()
54
71
?.metadata
55
- ?.releaseDate ? : LocalDate .now()
72
+ ?.releaseDate
73
+ ?.atStartOfDay(ZoneOffset .UTC ) ? : ZonedDateTime .now()
56
74
}
57
75
58
76
@Benchmark
@@ -73,7 +91,7 @@ class DashboardBenchmark : AbstractRestBenchmark() {
73
91
74
92
@Benchmark
75
93
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 ))) )
77
95
}
78
96
79
97
val pageableBooksOnDeck = Pageable .ofSize(DEFAULT_PAGE_SIZE )
@@ -87,14 +105,14 @@ class DashboardBenchmark : AbstractRestBenchmark() {
87
105
88
106
@Benchmark
89
107
fun getBooksLatest () {
90
- bookController.getAllBooksDeprecated (principal, page = pageableBooksLatest)
108
+ bookController.getBooks (principal, page = pageableBooksLatest, search = BookSearch () )
91
109
}
92
110
93
111
val pageableBooksRecentlyReleased = PageRequest .of(0 , DEFAULT_PAGE_SIZE , Sort .by(Sort .Order .desc(" metadata.releaseDate" )))
94
112
95
113
@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 )))) )
98
116
}
99
117
100
118
val pageableSeriesNew = Pageable .ofSize(DEFAULT_PAGE_SIZE )
@@ -115,6 +133,16 @@ class DashboardBenchmark : AbstractRestBenchmark() {
115
133
116
134
@Benchmark
117
135
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
+ )
119
147
}
120
148
}
0 commit comments