Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,4 @@ public void update(PostUpdateRequest postUpdateRequest) {
this.content = postUpdateRequest.content();
this.category = PostCategory.valueOf(postUpdateRequest.postCategory());
}

public void increaseViewCount(Long updateViewCount) {
this.viewCount += updateViewCount;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ default Post getById(Long id) {
@Query("UPDATE Post p SET p.likeCount = p.likeCount + 1 " +
"WHERE p.id = :postId")
void increaseLikeCount(@Param("postId") Long postId);

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("UPDATE Post p SET p.viewCount = p.viewCount + :count " +
"WHERE p.id = :postId")
void increaseViewCount(@Param("postId") Long postId, @Param("count") Long count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void updateViewCount(String key) {
log.info("updateViewCount Processing key: {} in thread: {}", key, Thread.currentThread().getName());
Long postId = redisUtils.getPostIdFromPostViewCountRedisKey(key);
Post post = postRepository.getById(postId);
post.increaseViewCount(redisService.getAndDelete(key));
postRepository.increaseViewCount(postId, redisService.getAndDelete(key));
log.info("updateViewCount Updated post id: {} with view count from key: {}", postId, key);
}
}