Skip to content

Commit

Permalink
refactor: PerformanceListener watch 생성 구현 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jul 26, 2024
1 parent 6885ad4 commit 05ff435
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ import org.springframework.context.ApplicationEventPublisher

class PerformanceListener(
private val applicationEventPublisher: ApplicationEventPublisher,
private var watch: StopWatch = StopWatch(),
) : ExecuteListener {
private val log = KotlinLogging.logger {}

companion object {
const val SLOW_QUERY_STANDARD = 5000000000L // 5 seconds
}

private var watch: StopWatch? = null
override fun executeStart(ctx: ExecuteContext) {
super.executeStart(ctx)
watch = StopWatch()
}

override fun executeEnd(ctx: ExecuteContext) {
super.executeEnd(ctx)
if (watch!!.split() > SLOW_QUERY_STANDARD) {
if (watch.split() > SLOW_QUERY_STANDARD) {
log.warn { "Slow Query Detected: \n${ctx.query()}" }
applicationEventPublisher.publishEvent(SlowQueryEvent(ctx.query().toString()))
}
Expand Down

0 comments on commit 05ff435

Please sign in to comment.