Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ AND b.id NOT IN (
LEFT JOIN rivals r ON b.fk_rival_id = r.id
WHERE (r.fk_first_user_id = :userId OR r.fk_second_user_id = :userId)
AND b.battle_status NOT IN ('REJECTED', 'PENDING', 'CANCELED')
ORDER BY b.started_at DESC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

정렬 결과의 일관성(Determinism)을 보장하기 위해 id와 같은 고유한 값을 보조 정렬 키로 추가하는 것이 좋습니다. 특히 페이징 처리가 나중에 추가될 경우, 동일한 started_at 값을 가진 레코드들의 순서가 보장되지 않으면 데이터 누락이나 중복 노출 문제가 발생할 수 있습니다. 또한, Native Query에서 OR 조건과 ORDER BY를 함께 사용하면 데이터량이 많아질 때 성능 저하가 발생할 수 있으므로 관련 컬럼의 인덱스 전략을 확인해 보시기 바랍니다.

Suggested change
ORDER BY b.started_at DESC
ORDER BY b.started_at DESC, b.id DESC

""", nativeQuery = true)
List<BattleJpaEntity> findByUserIdWithOutRejected(@Param("userId") Long userId);

Expand Down Expand Up @@ -124,6 +125,7 @@ AND b.end_at < NOW()
LEFT JOIN rivals r ON b.fk_rival_id = r.id
WHERE (r.fk_first_user_id = :userId OR r.fk_second_user_id = :userId)
AND b.battle_status = 'PENDING'
ORDER BY b.created_at DESC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

위의 findByUserIdWithOutRejected 메서드와 마찬가지로, 정렬의 결정성을 확보하기 위해 id를 보조 정렬 키로 추가하는 것을 권장합니다. created_at이 동일한 경우에도 일관된 순서로 결과를 반환할 수 있습니다.

Suggested change
ORDER BY b.created_at DESC
ORDER BY b.created_at DESC, b.id DESC

""", nativeQuery = true)
List<BattleJpaEntity> findPendingBattlesByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.Transport;
import com.process.clash.infrastructure.config.SocketIoProperties;
import com.process.clash.infrastructure.config.socket.SocketIoExceptionListener;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -26,6 +27,9 @@ public SocketIOServer socketIOServer(SocketIoAuthService authService) {
config.setPingTimeout(socketIoProperties.getPingTimeoutMs());
config.setTransports(Transport.WEBSOCKET);
config.setAuthorizationListener(authService::authorize);

config.setExceptionListener(new SocketIoExceptionListener());

return new SocketIOServer(config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.process.clash.infrastructure.config.socket;

import com.corundumstudio.socketio.listener.DefaultExceptionListener;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SocketIoExceptionListener extends DefaultExceptionListener {

@Override
public boolean exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception {
// Upgrade 헤더가 없는 잘못된 요청(HTTP 등)이 올 때 발생하는 로그 제어
if (e.getMessage() != null && e.getMessage().contains("not a WebSocket request")) {
log.warn("[Socket.IO] 비정상적인 연결 시도 차단: {} (IP: {})",
e.getMessage(), ctx.channel().remoteAddress());
return true; // 에러 전파를 여기서 중단하여 불필요한 스택 트레이스 방지
}
return super.exceptionCaught(ctx, e);
}
}
9 changes: 7 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ spring:
main:
web-application-type: servlet

task:
scheduling:
pool:
size: 10 # 각 스케줄러가 독립 스레드 사용

datasource:
url: ${DATABASE_URL}
username: ${DATABASE_USERNAME}
Expand Down Expand Up @@ -56,8 +61,8 @@ spring:
host: ${REDIS_HOST:localhost}
port: 6379
password: ${REDIS_PASSWORD}
connect-timeout: 30s
timeout: 30s
connect-timeout: 3s
timeout: 3s
lettuce:
pool:
max-active: 50
Expand Down
Loading