Skip to content

Commit fb555b6

Browse files
committed
perf: 세션 검증 성능 최적화 - 중복 컬렉션 열거 방지
- ChatRequestValidator.ValidateUserSessionAsync에서 Any() + Count() 패턴을 단일 ToList() + Count로 최적화 - 세션 스토리지 조회 시 중복 열거/쿼리 방지로 성능 개선 - 모든 기존 테스트 통과 (235/235)
1 parent 578399d commit fb555b6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ProjectVG.Application/Services/Chat/Validators/ChatRequestValidator.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,18 @@ private async Task ValidateUserSessionAsync(Guid userId)
7575
{
7676
try {
7777
// 사용자 ID를 기반으로 세션 조회
78-
var userSessions = await _sessionStorage.GetSessionsByUserIdAsync(userId.ToString()).ConfigureAwait(false);
78+
var userSessions = (await _sessionStorage
79+
.GetSessionsByUserIdAsync(userId.ToString())
80+
.ConfigureAwait(false))
81+
.ToList();
7982

80-
if (!userSessions.Any()) {
83+
if (userSessions.Count == 0) {
8184
_logger.LogWarning("유효하지 않은 사용자 세션: {UserId}", userId);
8285
throw new ValidationException(ErrorCode.SESSION_EXPIRED, "세션이 만료되었습니다. 다시 로그인해 주세요.");
8386
}
8487

8588
// 세션이 존재하면 로그 기록
86-
_logger.LogDebug("세션 검증 성공: {UserId}, 활성 세션 수: {SessionCount}", userId, userSessions.Count());
89+
_logger.LogDebug("세션 검증 성공: {UserId}, 활성 세션 수: {SessionCount}", userId, userSessions.Count);
8790
}
8891
catch (ValidationException) {
8992
throw; // 검증 예외는 그대로 전파

0 commit comments

Comments
 (0)