Skip to content

Commit

Permalink
release: 1.3.1 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Jan 19, 2025
2 parents 2d47300 + 279b81d commit e54870a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
import org.gitanimals.guild.app.request.CreateGuildRequest
import org.gitanimals.guild.app.response.GuildResponse
import org.gitanimals.guild.domain.GuildService
import org.gitanimals.guild.domain.RandomGuildCache
import org.gitanimals.guild.domain.request.CreateLeaderRequest
import org.rooftop.netx.api.Orchestrator
import org.rooftop.netx.api.OrchestratorFactory
Expand All @@ -19,6 +20,7 @@ class CreateGuildFacade(
private val guildService: GuildService,
private val identityApi: IdentityApi,
private val renderApi: RenderApi,
private val randomGuildCache: RandomGuildCache,
@Value("\${internal.secret}") internalSecret: String,
orchestratorFactory: OrchestratorFactory,
) {
Expand All @@ -40,7 +42,9 @@ class CreateGuildFacade(
TRACE_ID to MDC.get(TRACE_ID),
),
timeoutMillis = 1.minutes.inWholeMilliseconds,
).decodeResultOrThrow(GuildResponse::class)
).decodeResultOrThrow(GuildResponse::class).also {
randomGuildCache.updateForce()
}
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package org.gitanimals.guild.domain

import org.springframework.data.domain.Page

fun interface RandomGuildCache {
interface RandomGuildCache {

fun get(key: Int, text: String, pageNumber: Int, filter: SearchFilter): Page<Guild>

fun updateForce()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.gitanimals.guild.domain.GuildService
import org.gitanimals.guild.domain.GuildService.Companion.PAGE_SIZE
import org.gitanimals.guild.domain.RandomGuildCache
import org.gitanimals.guild.domain.SearchFilter
import org.slf4j.LoggerFactory
import org.springframework.context.event.ContextRefreshedEvent
import org.springframework.context.event.EventListener
import org.springframework.data.domain.Page
Expand All @@ -18,6 +19,7 @@ class InMemoryRandomGuildCache(
private val guildService: GuildService,
) : RandomGuildCache {

private val logger = LoggerFactory.getLogger(this::class.simpleName)
private lateinit var cache: Map<Int, List<Guild>>

override fun get(key: Int, text: String, pageNumber: Int, filter: SearchFilter): Page<Guild> {
Expand Down Expand Up @@ -55,6 +57,14 @@ class InMemoryRandomGuildCache(
return PageImpl(filter.sort(response), Pageable.ofSize(PAGE_SIZE), guilds.size.toLong())
}

override fun updateForce() {
runCatching {
updateRandom()
}.onFailure {
logger.error("Fail to force update in-memory guild cache", it)
}
}

@Scheduled(cron = ONCE_0AM_TIME)
@EventListener(ContextRefreshedEvent::class)
fun updateRandom() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gitanimals.guild.app.request.CreateGuildRequest
import org.gitanimals.guild.domain.GuildIcons
import org.gitanimals.guild.domain.GuildRepository
import org.gitanimals.guild.domain.GuildService
import org.gitanimals.guild.infra.InMemoryRandomGuildCache
import org.gitanimals.guild.supports.RedisContainer
import org.gitanimals.guild.supports.GuildSagaCapture
import org.gitanimals.guild.supports.MockApiConfiguration
Expand All @@ -37,6 +38,7 @@ import kotlin.time.Duration.Companion.seconds
CreateGuildFacade::class,
MockApiConfiguration::class,
GuildService::class,
InMemoryRandomGuildCache::class,
]
)
@DisplayName("CreateGuildFacade ํด๋ž˜์Šค์˜")
Expand Down

0 comments on commit e54870a

Please sign in to comment.