Skip to content

Commit 0036ad0

Browse files
committed
refactor: Redis 작업을 비동기 처리하여 WebFlux 블로킹 방지
1 parent 3212108 commit 0036ad0

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

nmnb-webflux/src/main/kotlin/nmnb/webflux/global/auth/service/AuthServiceImpl.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service
1414
import org.springframework.transaction.ReactiveTransactionManager
1515
import org.springframework.transaction.reactive.TransactionalOperator
1616
import reactor.core.publisher.Mono
17+
import reactor.core.scheduler.Schedulers
1718
import reactor.kotlin.core.publisher.switchIfEmpty
1819
import java.time.Instant
1920

@@ -87,8 +88,16 @@ class AuthServiceImpl(
8788
val now = Instant.now()
8889
val accessToken = jwtProvider.createAccessToken(now, email, deviceId)
8990
val refreshToken = jwtProvider.createRefreshToken(now, email, deviceId)
90-
return refreshTokenService.upsertRefreshToken(email, deviceId, refreshToken)
91-
.then(refreshTokenService.removeOldestTokenIfLimitExceeded(email))
91+
92+
val saveRefreshToken =
93+
Mono.fromCallable { refreshTokenService.upsertRefreshToken(email, deviceId, refreshToken) }
94+
.subscribeOn(Schedulers.boundedElastic())
95+
96+
val cleanupRefreshToken = Mono.fromCallable { refreshTokenService.removeOldestTokenIfLimitExceeded(email) }
97+
.subscribeOn(Schedulers.boundedElastic())
98+
99+
return saveRefreshToken
100+
.then(cleanupRefreshToken)
92101
.then(Mono.just(Pair(refreshToken, accessToken)))
93102
}
94103
}

0 commit comments

Comments
 (0)