Skip to content

Conversation

@ki-met-hoon
Copy link
Collaborator

Pull request

Related issue

Motivation and context

  • MongoDB와 RDB를 함께 사용하는 상황에서, UserChannel 엔티티의 last_read_id 필드 업데이트 시 JPA의 save() 메서드 대신 JDBC Template을 사용한 직접적인 UPDATE 쿼리를 선택했습니다.
    • 단일 필드 업데이트만 필요한 상황에서 전체 엔티티를 로드하고 저장하는 오버헤드 방지
    • SAVE 시 데이터 조회 및 전체 업데이트, 2번의 쿼리가 발생
    • 추가적으로 UserChannel Entity 중복 발생 방지
  • DisConnect 시에도 subscribe한 active channel이 삭제되어야 하기 때문에
    handleUserDisconnectionhandleChatUnsubscription method 추가

Solution

How has this been tested

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/CONTRIBUTING.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@ki-met-hoon ki-met-hoon added ✨ Feature 기능 추가 🎮 BE 백엔드 무조건 스프린트내에 해야하는 것들 labels Feb 18, 2025
@ki-met-hoon ki-met-hoon self-assigned this Feb 18, 2025
@netlify
Copy link

netlify bot commented Feb 18, 2025

Deploy Preview for jootalkpia canceled.

Name Link
🔨 Latest commit d3fd75b
🔍 Latest deploy log https://app.netlify.com/sites/jootalkpia/deploys/67b46f15ed0b1c0008cf5c0c

Copy link
Member

@bo-ram-bo-ram bo-ram-bo-ram left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! update를 통한 성능 개선 굿 떰업

handleStompCommand(StompHeaderAccessor.wrap(message));
}

public void handleChatUnsubscription(StompHeaderAccessor accessor) {
Copy link
Member

Choose a reason for hiding this comment

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

해당 메서드 @transactional처리 안해줘도 될까요?
updateChannelFromSession, removeTabFromChannel, updateLastReadId 3개의 변경이 발생되고 있어서요!
하나라도 실패해도 될까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현재 Redis 트랜잭션, 보상 트랜잭션 등 다양한 방안을 검토 중입니다!
추후에 리팩토링하겠습니다!

String sql = "UPDATE user_channel SET last_read_id = ? " +
"WHERE user_id = ? AND channel_id = ?";

jdbcTemplate.update(sql, lastReadId, Long.valueOf(userId), Long.valueOf(channelId));
Copy link
Member

Choose a reason for hiding this comment

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

updateLastReadId가 실행될 때 해당 row가 DB에 존재하는지 보장되지 않아서 존재하지 않으면 아무 일도 안 일어날텐데 예외처리까지는 너무 과할까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Optional 추가했고 없을 시 Default 값으로 0L 등록 로직 구현 완료했습니다!

@ki-met-hoon ki-met-hoon added the ♻️ Need To Refactor 추후 리팩토링이 필요한 이슈 및 논의 label Feb 18, 2025
@bo-ram-bo-ram bo-ram-bo-ram merged commit 16c7849 into dev Feb 18, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎮 BE 백엔드 ✨ Feature 기능 추가 ♻️ Need To Refactor 추후 리팩토링이 필요한 이슈 및 논의 무조건 스프린트내에 해야하는 것들

Projects

None yet

Development

Successfully merging this pull request may close these issues.

채널 Unsubscribe 시 Last Read Message ID 저장

3 participants