From 7ef27ebe221a0fcf259247efe1246b9766af4334 Mon Sep 17 00:00:00 2001 From: Menci Date: Sun, 12 Jan 2025 04:06:49 +0800 Subject: [PATCH] @Volatile List<> --- .../aqua/sega/maimai2/handler/GetGameRankingHandler.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/GetGameRankingHandler.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/GetGameRankingHandler.kt index c23f7bc1..2d3ac4f2 100644 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/GetGameRankingHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/GetGameRankingHandler.kt @@ -10,6 +10,7 @@ import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Component import java.time.LocalDateTime import java.time.format.DateTimeFormatter +import kotlin.concurrent.Volatile /** * @author samnyan (privateamusement@protonmail.com) @@ -20,7 +21,9 @@ class GetGameRankingHandler( private val queryFactory: JPAQueryFactory ) : BaseHandler { private data class MusicRankingItem(val musicId: Int, val weight: Long) - private var musicRankingCache: Array = emptyArray() + + @Volatile + private var musicRankingCache: List = emptyList() init { // To make sure the cache is initialized before the first request, @@ -52,7 +55,7 @@ class GetGameRankingHandler( .limit(QUREY_LIMIT) .fetch() .map { MusicRankingItem(it.get(cMusicId)!!, it.get(cUserCount)!!) } - .toTypedArray() + .toList() logger.info("Refreshed music ranking cache: ${musicRankingCache.size} items") }