Skip to content

Conversation

@LeeJaeYun7
Copy link
Collaborator

@LeeJaeYun7 LeeJaeYun7 commented Jul 16, 2023

  • Sse알림 기능에 Redis를 도입했습니다

Copy link
Collaborator

@f-lab-moony f-lab-moony left a comment

Choose a reason for hiding this comment

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

고생 많으셨습니다!
피드백을 좀 남겨 두었는데, 확인 후에 머지 하도록 할게요 ~

// @OneToOne 참조 관계를 설정하였습니다
@OneToOne
@JoinColumn(name = "NOTIFICATION_ID")
Notification notification;
Copy link
Collaborator

Choose a reason for hiding this comment

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

요거는 제가 그림이 약간 안그려지는데, 답변 하나에 알람이 하나만 만들어질 수 있는걸까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

음 제가 잘못한거 같네요. @OnetoOne이 아니라 @onetomany가 맞을 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

// Notification 엔티티와
// @OneToMany 참조 관계를 설정하였습니다
@OneToMany(mappedBy = "receiver")
@JsonManagedReference
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 어노테이션 사용하신 이유가 있을까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

순환 참조가 발생해서, 순환 참조를 방지하기 위해서 사용했습니다!

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)

@Setter
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Setter 사용은 지양하시는게 좋아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 삭제하겠습니다.
지양해야 하는 이유에 대해서도 알 수 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

@Entity
@Getter
@Builder
@RequiredArgsConstructor
Copy link
Collaborator

Choose a reason for hiding this comment

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

@RequiredArgsConstructor@AllArgsConstructor를 같이 쓰신 이유가 뭘까요 ?
그거와 별개로 두 어노테이션은 사용이 지양되는 녀석들이라 생성자 직접 생성을 권장드립니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 삭제하겠습니다.
사용을 지양해야 하는 이유에 대해서도 알 수 있을까요?

List<Notification> notifications = redisDao.getValuesForNotification(SseId);
if(notifications == null){
redisDao.setValuesForNotification(SseId);
}else{
Copy link
Collaborator

Choose a reason for hiding this comment

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

컨벤션을 따로 설정을 안하신 것 같은데, 구글 스타일 적용 해보는 게 어떨까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 이 부분 참고해보겠습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

적용 완료

if(notifications == null){
redisDao.setValuesForNotification(SseId);
}else{
for(Notification notification: notifications){
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 작업을 null이 아닐 때만 하게 하면 setValue 부분은 분기문 밖에서 공통으로 진행될 수 있지 않을까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

확인해보겠습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

// emitter가 null이 아닌 경우,
// 즉, receiver가 현재 로그인된 경우, receiver에게 바로 알림을 전송한다
if(emitter.isPresent()){
System.out.println("emitterId는?" + id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

이런 내부 로직들은 메서드로 추출해서 이름을 부여해주면 가독성을 더 높일 수 있어요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 확인했습니다

// emitter가 null인 경우,
// 즉, receiver가 현재 로그인되지 않은 경우,
// redisDao에서 SseId에 해당하는 notifications를 찾고 거기에 업데이트 한다
else{
Copy link
Collaborator

Choose a reason for hiding this comment

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

else문은 기본적으로 인덴트가 깊어지고 위의 조건을 인지하고 있어야 하기 때문에 가독성을 떨어뜨려요.
위의 if문 안의 로직에서 return으로 플로우를 끊고 아래 로직은 else문 바깥에서 진행하는 게 어떨까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 확인했습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

.content(content)
.isRead(false)
.build();
return notification;
Copy link
Collaborator

Choose a reason for hiding this comment

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

바로 리턴해도 되지 않을까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이 부분에서 버그가 발생해서 테스트 도중 이렇게 작성해서 커밋한것 같습니다.
현재 Notification Entity의 @id 칼럼에 @GeneratedValue(strategy = GenerationType.IDENTITY)라고 설정되어 있는데,

notificationRepository.save(notification)으로
생성된 notification 객체를 저장하려고 할 때, id가 null이라는 문제가 발생하더라고요

제 생각에는 h2 데이터베이스에서 auto increment로 자동으로 생성해줘야 하는게 아닌가 싶었는데, 안되는 것 같아서 문제 해결중입니다

}

@Bean
public RedisTemplate<String, List<Notification>> redisTemplateForNotification() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@f-lab-moony f-lab-moony left a comment

Choose a reason for hiding this comment

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

고생 많으셨습니다 ~ 머지 해둘게요!
라고 하려고 했는데 베이스 브랜치랑 충동리 나서 머지가 불가능하네요 ~? 혹시 따로 main 브랜치에 작업하셨을까요 ?

public abstract class BaseTimeEntity {

@CreatedDate
@JsonIgnore
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JsonIgnore 는 왜 추가가 됐을까요 ?

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에서 직렬화, 역직렬화 할 때 에러가 발생하더라고요
그래서 추가했습니다!

@LeeJaeYun7 LeeJaeYun7 merged commit 93af531 into main Jul 25, 2023
f-lab-moony added a commit that referenced this pull request Aug 4, 2023
@LeeJaeYun7 LeeJaeYun7 deleted the feat/sseAlarm branch August 15, 2023 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants