mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-11 04:47:26 +08:00
@Volatile List<>
This commit is contained in:
@@ -10,6 +10,7 @@ import org.springframework.scheduling.annotation.Scheduled
|
|||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
import kotlin.concurrent.Volatile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
@@ -20,7 +21,9 @@ class GetGameRankingHandler(
|
|||||||
private val queryFactory: JPAQueryFactory
|
private val queryFactory: JPAQueryFactory
|
||||||
) : BaseHandler {
|
) : BaseHandler {
|
||||||
private data class MusicRankingItem(val musicId: Int, val weight: Long)
|
private data class MusicRankingItem(val musicId: Int, val weight: Long)
|
||||||
private var musicRankingCache: Array<MusicRankingItem> = emptyArray()
|
|
||||||
|
@Volatile
|
||||||
|
private var musicRankingCache: List<MusicRankingItem> = emptyList()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// To make sure the cache is initialized before the first request,
|
// To make sure the cache is initialized before the first request,
|
||||||
@@ -52,7 +55,7 @@ class GetGameRankingHandler(
|
|||||||
.limit(QUREY_LIMIT)
|
.limit(QUREY_LIMIT)
|
||||||
.fetch()
|
.fetch()
|
||||||
.map { MusicRankingItem(it.get(cMusicId)!!, it.get(cUserCount)!!) }
|
.map { MusicRankingItem(it.get(cMusicId)!!, it.get(cUserCount)!!) }
|
||||||
.toTypedArray()
|
.toList()
|
||||||
|
|
||||||
logger.info("Refreshed music ranking cache: ${musicRankingCache.size} items")
|
logger.info("Refreshed music ranking cache: ${musicRankingCache.size} items")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user