From da6aefa74d51fc547a74f1d5882719732372ef44 Mon Sep 17 00:00:00 2001 From: Stedoss Date: Sun, 3 Nov 2024 15:22:33 +0000 Subject: [PATCH] Allow replay cache to be disabled with env variable --- .../nisemoe/nise/scheduler/ImportScores.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportScores.kt b/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportScores.kt index 7052e9a..1c60490 100644 --- a/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportScores.kt +++ b/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportScores.kt @@ -55,6 +55,7 @@ class ImportScores( private val messagingTemplate: SimpMessagingTemplate, private val replayCacheService: ReplayCacheService, ) : InitializingBean { + val replayCacheEnabled = (System.getenv("REPLAY_CACHE_ENABLED") ?: "0") != "0" private val userToUpdateBucket = mutableListOf() @@ -788,20 +789,22 @@ class ImportScores( ) } - // Insert into replay cache - val replayCacheReplay = ReplayCacheReplay( - score.best_id, - beatmapId, - score.user_id.toInt(), - Base64.getDecoder().decode(scoreReplay.content), - Mod.combineModStrings(score.mods), - ) - val replayCacheInsertSuccess = replayCacheService.insertReplay(replayCacheReplay) + if (replayCacheEnabled) { + // Insert into replay cache + val replayCacheReplay = ReplayCacheReplay( + score.best_id, + beatmapId, + score.user_id.toInt(), + Base64.getDecoder().decode(scoreReplay.content), + Mod.combineModStrings(score.mods), + ) + val replayCacheInsertSuccess = replayCacheService.insertReplay(replayCacheReplay) - if (replayCacheInsertSuccess) { - logger.info("Inserted replay ${score.id} into replay cache") - } else { - logger.error("Could not insert replay ${score.id} into replay cache") + if (replayCacheInsertSuccess) { + logger.info("Inserted replay ${score.id} into replay cache") + } else { + logger.error("Could not insert replay ${score.id} into replay cache") + } } this.statistics.scoresWithReplayAndAnalyzed++