@@ -22,6 +22,7 @@ import org.opensearch.search.sort.SortBuilders
22
22
import org.opensearch.search.sort.SortOrder
23
23
import org.springframework.context.ApplicationListener
24
24
import org.springframework.context.event.ContextRefreshedEvent
25
+ import java.lang.System.currentTimeMillis
25
26
import java.time.LocalDate
26
27
import java.util.*
27
28
import java.util.concurrent.TimeUnit
@@ -277,31 +278,55 @@ open class ElasticsearchService(private val esBehandlingRepository: EsBehandling
277
278
}
278
279
279
280
open fun countIkkeTildelt (ytelse : Ytelse , type : Type ): Long {
280
- return countByStatusYtelseAndType(IKKE_TILDELT , ytelse, type)
281
+ return runWithTiming(method = ::countIkkeTildelt.name) {
282
+ countByStatusYtelseAndType(IKKE_TILDELT , ytelse, type)
283
+ }
281
284
}
282
285
283
286
open fun countTildelt (ytelse : Ytelse , type : Type ): Long {
284
- return countByStatusYtelseAndType(TILDELT , ytelse, type)
287
+ return runWithTiming(method = ::countTildelt.name) {
288
+ countByStatusYtelseAndType(TILDELT , ytelse, type)
289
+ }
285
290
}
286
291
287
292
open fun countSendtTilMedunderskriver (ytelse : Ytelse , type : Type ): Long {
288
- return countByStatusYtelseAndType(SENDT_TIL_MEDUNDERSKRIVER , ytelse, type)
293
+ return runWithTiming(method = ::countSendtTilMedunderskriver.name) {
294
+ countByStatusYtelseAndType(SENDT_TIL_MEDUNDERSKRIVER , ytelse, type)
295
+ }
289
296
}
290
297
291
298
open fun countMedunderskriverValgt (ytelse : Ytelse , type : Type ): Long {
292
- return countByStatusYtelseAndType(MEDUNDERSKRIVER_VALGT , ytelse, type)
299
+ return runWithTiming(method = ::countMedunderskriverValgt.name) {
300
+ countByStatusYtelseAndType(MEDUNDERSKRIVER_VALGT , ytelse, type)
301
+ }
293
302
}
294
303
295
304
open fun countReturnertTilSaksbehandler (ytelse : Ytelse , type : Type ): Long {
296
- return countByStatusYtelseAndType(RETURNERT_TIL_SAKSBEHANDLER , ytelse, type)
305
+ return runWithTiming(method = ::countReturnertTilSaksbehandler.name) {
306
+ countByStatusYtelseAndType(RETURNERT_TIL_SAKSBEHANDLER , ytelse, type)
307
+ }
297
308
}
298
309
299
310
open fun countAvsluttet (ytelse : Ytelse , type : Type ): Long {
300
- return countByStatusYtelseAndType(FULLFOERT , ytelse, type)
311
+ return runWithTiming(method = ::countAvsluttet.name) {
312
+ countByStatusYtelseAndType(FULLFOERT , ytelse, type)
313
+ }
301
314
}
302
315
303
316
open fun countSattPaaVent (ytelse : Ytelse , type : Type ): Long {
304
- return countByStatusYtelseAndType(SATT_PAA_VENT , ytelse, type)
317
+ return runWithTiming(method = ::countSattPaaVent.name) {
318
+ countByStatusYtelseAndType(SATT_PAA_VENT , ytelse, type)
319
+ }
320
+ }
321
+
322
+ private fun <T > runWithTiming (method : String , block : () -> T ): T {
323
+ val start = currentTimeMillis()
324
+ try {
325
+ return block.invoke()
326
+ } finally {
327
+ val end = currentTimeMillis()
328
+ logger.debug(" Time it took to call $method : ${end - start} millis" )
329
+ }
305
330
}
306
331
307
332
private fun countByStatusYtelseAndType (status : EsStatus , ytelse : Ytelse , type : Type ): Long {
@@ -313,6 +338,7 @@ open class ElasticsearchService(private val esBehandlingRepository: EsBehandling
313
338
}
314
339
315
340
open fun countAntallSaksdokumenterIAvsluttedeBehandlingerMedian (ytelse : Ytelse , type : Type ): Double {
341
+ val start = currentTimeMillis()
316
342
val baseQuery: BoolQueryBuilder = QueryBuilders .boolQuery()
317
343
baseQuery.must(QueryBuilders .termQuery(EsBehandling ::status.name, FULLFOERT ))
318
344
baseQuery.must(QueryBuilders .termQuery(EsBehandling ::ytelseId.name, ytelse.id))
@@ -324,7 +350,14 @@ open class ElasticsearchService(private val esBehandlingRepository: EsBehandling
324
350
}
325
351
.toList()
326
352
327
- return getMedian(saksdokumenterPerAvsluttetBehandling)
353
+ val medianStart = currentTimeMillis()
354
+ val median = getMedian(saksdokumenterPerAvsluttetBehandling)
355
+ val medianEnd = currentTimeMillis()
356
+ logger.debug(" Time it took to calculate median for list with ${saksdokumenterPerAvsluttetBehandling.size} elements: ${medianEnd - medianStart} millis" )
357
+
358
+ val end = currentTimeMillis()
359
+ logger.debug(" Time it took to call ${::countAntallSaksdokumenterIAvsluttedeBehandlingerMedian.name} : ${end - start} millis" )
360
+ return median
328
361
}
329
362
330
363
open fun countLedigeOppgaverMedUtgaattFristByCriteria (criteria : CountLedigeOppgaverMedUtgaattFristSearchCriteria ): Int {
0 commit comments