Skip to content

[IDLE-563] Redis 세션 공유 기반 알림 필터링 및 읽음처리 정상화#269

Merged
mjj111 merged 6 commits intodevelopfrom
feat/IDLE-563
Apr 14, 2025
Merged

[IDLE-563] Redis 세션 공유 기반 알림 필터링 및 읽음처리 정상화#269
mjj111 merged 6 commits intodevelopfrom
feat/IDLE-563

Conversation

@mjj111
Copy link
Copy Markdown
Member

@mjj111 mjj111 commented Apr 14, 2025

1. 📄 Summary

  • Redis를 통한 현재 채팅방 입장자 id를 공유하여, 알림 전달 필터링
  • 채팅방 목록 쿼리를 내가 안읽은 메시지기반으로 수정
  • 읽음 처리 동작 정상화
  • 사용하지 않는 API 삭제 (단일 채팅방 요약정보 조회)

2. 🤔 고민했던 점

  1. 채팅방 내에서 접속한 사용자와 접속하지 않은 사용자를 구분해, 불필요한 알림 푸시를 줄이는 방식을 고민했습니다.

  2. WebSocket 기반 시스템에서 세션 종료나 예상치 못한 끊김 등으로 Redis 정리가 누락되는 상황을 방지할 수 있을지에 대한 고민이 있었습니다.

  3. Redis에 사용자 정보를 저장할 때 어떻게 만료(TTL)를 활용하여 자동 정리를 유도할지, 그리고 이는 실사용자 경험에 영향을 주지 않을지 고려했습니다.

3. 💡 알게된 점, 궁금한 점

  • WebSocket 연결 시점과 종료 시점에 Redis를 통해 세션을 관리하면, 실시간 사용자 상태 추적이 가능한 것을 알게되었고, STOMP기반이기 때문에 handshake와 connection이 닫기는 이벤트에 따라 Redis에 id값을 관리하도록 하였습니다.

  • Redis에 TTL(Time-To-Live)을 설정해두면, 예기치 못한 예외 상황에도 리소스가 자동으로 정리되는 이점이 있음을 알게되었습니다.
    이에따라, 사용자가 정상적으로 접속 종료하지 않더라도 세션 정보가 과도하게 쌓이지 않고 일정 시간 뒤 정리되도록 하였습니다.

Summary by CodeRabbit

  • 새로운 기능
    • 채팅 연결 시 사용자 세션이 생성되고, 24시간 유지되며, 연결 해제 시 자동으로 정리되는 기능이 추가되었습니다.
    • 채팅 메시지 발송 및 세션 관리 기능이 향상되었습니다.
  • 버그 수정
    • 특정 채팅방 정보 조회 기능이 제거되어 인터페이스가 일관되게 정리되었습니다.
  • 리팩토링
    • 채팅 메시지 전송 및 조회 처리 과정이 간소화되어 성능과 안정성이 개선되었습니다.
  • 변경사항
    • 채팅방 검색 기능이 개선되어 사용자 ID에 따라 필터링할 수 있게 되었습니다.

@mjj111 mjj111 added the 🎯리팩토링 리팩토링 및 고도화 이슈 label Apr 14, 2025
@mjj111 mjj111 self-assigned this Apr 14, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2025

Walkthrough

이 PR은 여러 컴포넌트에서 ChatRedisPublisher를 ChatRedisTemplate로 교체하는 작업을 포함합니다. ChatFacadeService와 ChatRedisSubscriber는 새 템플릿을 사용하도록 수정되었으며, ChatRedisTemplate에는 세션 관리(isChatting, delete, setSession) 관련 새로운 메서드들이 추가되었습니다. 또한, 일부 저장소(repository) SQL 쿼리에 필터 조건이 추가되고, 트랜잭션 관리 어노테이션이 개선되었습니다. API와 컨트롤러에서는 단일 채팅방 요약을 반환하는 메서드들이 제거되었으며, WebSocket 핸드셰이크 및 종료 시 Redis 세션 관리 기능이 도입되었습니다.

Changes

Files Change Summary
idle-application/.../ChatFacadeService.kt, idle-domain/.../ChatRedisSubscriber.kt, idle-domain/.../ChatRedisTemplate.kt ChatRedisPublisher가 ChatRedisTemplate로 교체됨. 생성자 파라미터 및 메서드 호출(Publish, 메시지 타입 상수)이 업데이트되었으며, ChatRedisTemplate에 세션 관리 메서드(isChatting, delete, setSession)가 추가됨.
idle-domain/.../ChatMessageRepository.kt, idle-domain/.../ChatRoomRepository.kt 저장소 메서드 어노테이션이 @Modifying에서 @transactional@Modifying(clearAutomatically = true)로 변경됨. SQL 쿼리에 receiverId 조건 추가 및 centerFindSingleChatRoom 메서드 제거, centerFindChatRooms 메서드 추가됨.
idle-presentation/.../ChatCarerApi.kt, idle-presentation/.../ChatCenterApi.kt, idle-presentation/.../ChatCarerController.kt, idle-presentation/.../ChatCenterController.kt 단일 채팅방 요약 정보를 반환하는 carerSingleChatroomSummary 메서드들이 제거됨.
idle-presentation/.../ChatHandshakeInterceptor.kt, idle-presentation/.../WebSocketDisconnectListener.kt ChatHandshakeInterceptor에 ChatRedisTemplate 의존성이 추가되어 핸드셰이크 시 Redis 세션이 설정됨. WebSocketDisconnectListener가 추가되어 세션 종료 이벤트 발생 시 Redis에서 세션 데이터를 삭제함.

Sequence Diagram(s)

sequenceDiagram
    participant U as 사용자
    participant CF as ChatFacadeService
    participant CRT as ChatRedisTemplate

    U->>CF: sendMessage(message)
    CF->>CRT: isChatting(message.receiverId)
    alt 수신자가 채팅 중인 경우
        CF-->>U: 메시지 발행 생략 (조기 종료)
    else 채팅 중이 아닐 경우
        CF->>CRT: publish(message)
        CF-->>U: 메시지 발행 완료
    end
Loading
sequenceDiagram
    participant D as Disconnect Event
    participant WSDL as WebSocketDisconnectListener
    participant CRT as ChatRedisTemplate

    D->>WSDL: handleDisconnect(event)
    WSDL->>WSDL: event에서 userId 추출
    alt userId가 존재하는 경우
        WSDL->>CRT: delete(userId)
    else userId가 없을 경우
        WSDL-->>D: 작업 없음
    end
Loading

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5093ad9 and 7de41bc.

📒 Files selected for processing (1)
  • idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatRedisTemplate.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and analyze
🔇 Additional comments (5)
idle-domain/src/main/kotlin/com/swm/idle/domain/chat/event/ChatRedisTemplate.kt (5)

9-10: 적절한 임포트 추가

Duration과 UUID 관련 기능을 사용하기 위한 적절한 임포트가 추가되었습니다.


13-13: 클래스 이름 변경이 적절합니다

ChatRedisPublisher에서 ChatRedisTemplate으로의 이름 변경은 클래스의 확장된 기능을 더 잘 반영합니다. 단순히 메시지를 발행하는 것뿐만 아니라 세션 관리 기능도 포함하게 되었기 때문입니다.


17-19: 사용자 활성 상태 확인 메서드 구현이 적절합니다

현재 사용자가 채팅 세션에 활성화되어 있는지 확인하는 메서드가 잘 구현되었습니다. 이 메서드는 Redis의 키 존재 여부를 확인하여 사용자가 채팅 중인지 효과적으로 판단합니다.


21-23: 세션 삭제 메서드 구현이 적절합니다

사용자 세션을 삭제하는 방법이 간결하고 명확하게 구현되었습니다. 사용자가 채팅방을 나가거나 연결이 끊어졌을 때 세션 정보를 정리하는 데 효과적으로 사용될 수 있습니다.


13-27: PR 목표에 부합하는 구현

Redis를 통한 세션 공유 기반 알림 필터링 기능 구현이라는 PR 목표에 잘 부합하는 구현입니다. 사용자의 채팅 참여 상태를 Redis를 통해 관리함으로써 불필요한 알림 전송을 방지할 수 있습니다. TTL 기능을 활용하여 세션 정보가 자동으로 정리되도록 한 점도 좋은 접근법입니다.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mjj111 mjj111 changed the title [IDLE-561] Redis 세션 공유 기반 알림 필터링 및 [IDLE-563] Redis 세션 공유 기반 알림 필터링 및 Apr 14, 2025
coderabbitai[bot]

This comment was marked as resolved.

@mjj111 mjj111 changed the title [IDLE-563] Redis 세션 공유 기반 알림 필터링 및 [IDLE-563] Redis 세션 공유 기반 알림 필터링 및 Apr 14, 2025
@mjj111 mjj111 changed the title [IDLE-563] Redis 세션 공유 기반 알림 필터링 및 [IDLE-563] Redis 세션 공유 기반 알림 필터링 및 읽음처리 정상화 Apr 14, 2025
@sonarqubecloud
Copy link
Copy Markdown

@mjj111 mjj111 merged commit 4f07545 into develop Apr 14, 2025
5 of 6 checks passed
@mjj111 mjj111 deleted the feat/IDLE-563 branch April 14, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎯리팩토링 리팩토링 및 고도화 이슈

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant