From 2d3b7b0817e15e0d23a65d238c17e4b05a2e1b7d Mon Sep 17 00:00:00 2001 From: "nise.moe" Date: Thu, 22 Feb 2024 15:35:34 +0100 Subject: [PATCH] Fixed algorithm error with calculating canUpdate due to wrapping around the day at midnight --- .../com/nisemoe/nise/service/UpdateUserQueueService.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nise-backend/src/main/kotlin/com/nisemoe/nise/service/UpdateUserQueueService.kt b/nise-backend/src/main/kotlin/com/nisemoe/nise/service/UpdateUserQueueService.kt index 95164c7..3fdd28e 100644 --- a/nise-backend/src/main/kotlin/com/nisemoe/nise/service/UpdateUserQueueService.kt +++ b/nise-backend/src/main/kotlin/com/nisemoe/nise/service/UpdateUserQueueService.kt @@ -8,6 +8,7 @@ import org.jooq.DSLContext import org.springframework.http.ResponseEntity import org.springframework.messaging.simp.SimpMessagingTemplate import org.springframework.stereotype.Service +import java.time.Duration import java.time.OffsetDateTime import java.time.ZoneOffset @@ -43,12 +44,13 @@ class UpdateUserQueueService( .limit(1) .fetchOneInto(OffsetDateTime::class.java) - var canUpdate = !isProcessing - if(lastCompletedUpdateQueue != null) { + var canUpdate = !isProcessing; + if (lastCompletedUpdateQueue != null) { val now = OffsetDateTime.now(ZoneOffset.UTC) - val hoursSinceLastUpdate = now.hour - lastCompletedUpdateQueue.hour + val duration = Duration.between(lastCompletedUpdateQueue, now) + val hoursSinceLastUpdate = duration.toHours() - if(hoursSinceLastUpdate < USER_UPDATE_INTERVAL_HOURS) + if (hoursSinceLastUpdate < USER_UPDATE_INTERVAL_HOURS) canUpdate = false }