Skip to content

Commit ea627bc

Browse files
committed
refactor 게시물 조회시 사용자 좋아요 상태 반영
- redis에서 먼저 캐싱을 조회하고, Repo를 조회하여 최신인 현재 저장된 캐싱 값을 먼저 상태로 반환하도록 설정.
1 parent d325d3e commit ea627bc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/io/crops/warmletter/domain/share/service/SharePostLikeService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public SharePostLikeResponse getLikeCountAndStatus(Long sharePostId) {
2727
if (sharePostId == null)
2828
throw new ShareInvalidInputValue();
2929

30-
return sharePostLikeRepository.getLikeCountAndStatus(sharePostId,memberId);
30+
boolean isLikedInRedis = postLikeRedisManager.isLiked(sharePostId,memberId);
31+
32+
SharePostLikeResponse response = sharePostLikeRepository.getLikeCountAndStatus(sharePostId,memberId);
33+
34+
if (isLikedInRedis != response.isLiked()) {
35+
return new SharePostLikeResponse(response.getLikeCount(), isLikedInRedis);
36+
}
37+
38+
return response;
3139
}
3240
}

0 commit comments

Comments
 (0)