@@ -14,6 +14,7 @@ import org.jooq.kotlin.ge
14
14
import org.jooq.kotlin.le
15
15
import org.springframework.stereotype.Repository
16
16
import ru.ifmo.se.dating.exception.NotFoundException
17
+ import ru.ifmo.se.dating.logging.Log.Companion.autoLog
17
18
import ru.ifmo.se.dating.pagging.Page
18
19
import ru.ifmo.se.dating.people.model.Location
19
20
import ru.ifmo.se.dating.people.model.Person
@@ -30,6 +31,8 @@ import ru.ifmo.se.dating.storage.FetchPolicy
30
31
import ru.ifmo.se.dating.storage.TxEnv
31
32
import ru.ifmo.se.dating.storage.jooq.JooqDatabase
32
33
import ru.ifmo.se.dating.storage.jooq.withPolicy
34
+ import java.time.LocalDate
35
+ import java.time.OffsetDateTime
33
36
34
37
@Suppress(" TooManyFunctions" )
35
38
@Repository
@@ -40,6 +43,8 @@ class JooqPersonStorage(
40
43
private val interests : InterestStorage ,
41
44
private val locations : LocationStorage ,
42
45
) : PersonStorage {
46
+ private val log = autoLog()
47
+
43
48
@Suppress(" CyclomaticComplexMethod" )
44
49
override suspend fun upsert (draft : Person .Draft ): PersonVariant = txEnv.transactional {
45
50
database.only {
@@ -108,7 +113,7 @@ class JooqPersonStorage(
108
113
}
109
114
}.let { }
110
115
111
- @Suppress(" LongMethod" )
116
+ @Suppress(" LongMethod" , " CyclomaticComplexMethod " , " CognitiveComplexMethod " )
112
117
override fun selectFilteredReady (
113
118
page : Page ,
114
119
filter : PersonService .Filter ,
@@ -119,19 +124,31 @@ class JooqPersonStorage(
119
124
120
125
filter.lastName?.let { cond = cond.and (PERSON .LAST_NAME .likeRegex(it.pattern)) }
121
126
122
- cond = cond.and (PERSON .HEIGHT .ge(filter.height.first))
123
- cond = cond.and (PERSON .HEIGHT .le(filter.height.last))
127
+ if (filter.height.first != Int .MIN_VALUE ) {
128
+ cond = cond.and (PERSON .HEIGHT .ge(filter.height.first))
129
+ }
130
+ if (filter.height.last != Int .MAX_VALUE ) {
131
+ cond = cond.and (PERSON .HEIGHT .le(filter.height.last))
132
+ }
124
133
125
- cond = cond.and (PERSON .BIRTHDAY .ge(filter.birthday.start))
126
- cond = cond.and (PERSON .BIRTHDAY .le(filter.birthday.endInclusive))
134
+ if (filter.birthday.start != LocalDate .MIN ) {
135
+ cond = cond.and (PERSON .BIRTHDAY .ge(filter.birthday.start))
136
+ }
137
+ if (filter.birthday.endInclusive != LocalDate .MAX ) {
138
+ cond = cond.and (PERSON .BIRTHDAY .le(filter.birthday.endInclusive))
139
+ }
127
140
128
141
filter.facultyId?.let { cond = cond.and (PERSON .FACULTY_ID .eq(it.number)) }
129
142
130
- cond = cond.and (PERSON .UPDATE_MOMENT .ge(filter.updated.start))
131
- cond = cond.and (PERSON .UPDATE_MOMENT .le(filter.updated.endInclusive))
143
+ if (filter.updated.start != OffsetDateTime .MIN ) {
144
+ cond = cond.and (PERSON .UPDATE_MOMENT .ge(filter.updated.start))
145
+ }
146
+ if (filter.updated.endInclusive != OffsetDateTime .MAX ) {
147
+ cond = cond.and (PERSON .UPDATE_MOMENT .le(filter.updated.endInclusive))
148
+ }
132
149
133
150
val picturesCountQuery =
134
- select( DSL .count() )
151
+ selectCount( )
135
152
.from(PICTURE )
136
153
.where(
137
154
PICTURE .IS_REFERENCED .eq(true )
@@ -158,6 +175,8 @@ class JooqPersonStorage(
158
175
.where(cond)
159
176
.offset(page.offset)
160
177
.limit(page.limit)
178
+ .also { log.warn(" Executed SQL: ${it.sql} " ) }
179
+ .also { log.warn(" BindValues: ${it.bindValues} " ) }
161
180
}
162
181
.map { it.enrichToModel() as Person }
163
182
.filter { filter.area == null || filter.area.contains(it.location.coordinates) }
0 commit comments