Skip to content

Commit

Permalink
[FIX] fix comment count logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CokeLee777 committed Jan 10, 2024
1 parent 5837133 commit ed78683
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public Comment createComment(
Comment comment = Comment.createComment(member, post, createCommentRequest.getDescription());
try {
PostCountVO postCountVO =
new PostCountVO(post.getViewCount(), post.getLikeCount(), post.getCommentCount() + 1);
new PostCountVO(post.getViewCount(), post.getLikeCount(), post.getCommentCount());
PostCountVO cachedPostCountVO = postCountRedisRepository.findOrPutPostCountVO(String.valueOf(postId), postCountVO);
cachedPostCountVO.addCommentCount(1);
// update comment count to cache
postCountRedisRepository.modifyPostCountVOAboutLikeCount(String.valueOf(postId), postCountVO);
postCountRedisRepository.modifyPostCountVOAboutLikeCount(String.valueOf(postId), cachedPostCountVO);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/dailyon/snsservice/vo/PostCountVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public class PostCountVO implements Serializable {
public void addLikeCount(Integer count) {
this.likeCount += count;
}

public void addCommentCount(Integer count) {
this.commentCount += count;
}
}

0 comments on commit ed78683

Please sign in to comment.