mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
Merge pull request #69 from dalbodeule/develop
debug DiscordGuildCache (x2)
This commit is contained in:
commit
3ab6a4031a
@ -23,6 +23,9 @@ import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import space.mori.chzzk_bot.common.services.UserService
|
||||
import space.mori.chzzk_bot.webserver.routes.*
|
||||
import space.mori.chzzk_bot.webserver.utils.CachedGuilds
|
||||
import space.mori.chzzk_bot.webserver.utils.DiscordGuildCache
|
||||
import space.mori.chzzk_bot.webserver.utils.Guild
|
||||
import java.time.Duration
|
||||
|
||||
val dotenv = dotenv {
|
||||
@ -125,6 +128,11 @@ val server = embeddedServer(Netty, port = 8080, ) {
|
||||
it.owner
|
||||
}.map { it.id }
|
||||
))
|
||||
DiscordGuildCache.addGuild(guilds.associate {
|
||||
it.id to CachedGuilds(
|
||||
Guild(it.id, it.name, it.icon, it.banner)
|
||||
)
|
||||
})
|
||||
|
||||
redirects[principal.state]?.let { redirect ->
|
||||
call.respondRedirect(redirect)
|
||||
|
@ -18,7 +18,7 @@ object DiscordGuildCache {
|
||||
suspend fun getCachedGuilds(guildId: String): Guild? {
|
||||
val now = Instant.now()
|
||||
|
||||
return if(cache.isNotEmpty() && cache[guildId]?.timestamp?.plusSeconds(EXP_SECONDS)?.isAfter(now) == true) {
|
||||
return if(cache.isNotEmpty() && cache[guildId]?.timestamp?.plusSeconds(EXP_SECONDS)?.isAfter(now) == false) {
|
||||
cache[guildId]?.guild
|
||||
} else {
|
||||
fetchAllGuilds()
|
||||
@ -61,6 +61,10 @@ object DiscordGuildCache {
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
|
||||
fun addGuild(guilds: Map<String, CachedGuilds>) {
|
||||
cache.putAll(guilds)
|
||||
}
|
||||
}
|
||||
|
||||
data class CachedGuilds(
|
||||
|
Loading…
x
Reference in New Issue
Block a user