Feat : RoomMember 엔티티 필드 제거 기반 redis 연동 (#144) #145
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📌 개요
RoomMember엔티티의 실시간 상태 필드를 제거한 후,이번 PR에서는 Redis를 활용한 실시간 참가자 추적 하도록했습니다.
🔨 작업 내용
1. Redis 실시간 상태 관리
RedisSessionStore: Redis CRUD 레이어UserSessionService: WebSocket 세션 생명주기 관리RoomParticipantService: 방별 참가자 관리WebSocketEventListener: 연결/해제 이벤트 처리WebSocketMessageController: Heartbeat, 방 입장/퇴장 처리2. DB 업데이트 로직 제거 (총 6곳)
RoomService수정 (임시로 주석 처리 했습니다! 활용 가능성이 있을 수 있어서)createRoom():incrementParticipant()주석 처리joinRoom():incrementParticipant()주석 처리 (2곳)leaveRoom():decrementParticipant()주석 처리handleHostLeaving():decrementParticipant()주석 처리 (2곳)kickMember():decrementParticipant()주석 처리➡️ DB와 Redis 간 동기화 문제 해결
3. 실시간 참가자 수 조회 구현
getBulkRoomOnlineUserCounts(List<Long> roomIds)추가 → N+1 방지toRoomResponse(Room)toRoomResponseList(List<Room>)toRoomDetailResponse(Room, List<RoomMember>)toMyRoomResponse(Room, RoomRole)toMyRoomResponseList(List<Room>, Long)RoomResponse.from(Room, long currentParticipants)RoomDetailResponse.of(Room, long currentParticipants, List<RoomMemberResponse>)MyRoomResponse.of(Room, long currentParticipants, RoomRole)4. Controller 수정
POST /api/rooms→toRoomResponse()GET /api/rooms→toRoomResponseList()GET /api/rooms/{roomId}→toRoomDetailResponse()GET /api/rooms/my→toMyRoomResponseList()GET /api/rooms/popular→toRoomResponseList()5. 테스트 코드 수정
toRoomResponse(),toRoomResponseList(),toRoomDetailResponse(),toMyRoomResponseList()verify 추가🔗 관련 이슈
Closes #144
📝 참고 사항
아키텍처 변경
Before (PR #1 이전)
RoomMember.isOnlineRoom.currentParticipants(부정확)After (PR #2)
ws:user:{userId}→WebSocketSessionInfo(TTL 6분)ws:session:{sessionId}→ userIdws:room:{roomId}:users→ 참가자 SetRoom.currentParticipants필드 유지 (단, 업데이트 안 함)성능 개선
getBulkRoomOnlineUserCounts()도입Breaking Changes
API 응답 변경
currentParticipants→ Redis 기반 실시간 값 반환Room.currentParticipants는 현재 업데이트하지 않는 상태인데 통계용 배치에 필요하면 활용하고, 없다면 완전 제거 하겠습니다향후 작업 예정
findOnlineMembersByRoomId쿼리 Redis 조회로 대체✅ 체크리스트