diff --git a/spring-board/src/main/java/com/example/springboard/domain/comment/service/CommentService.java b/spring-board/src/main/java/com/example/springboard/domain/comment/service/CommentService.java index 0f19636..2b5ba99 100644 --- a/spring-board/src/main/java/com/example/springboard/domain/comment/service/CommentService.java +++ b/spring-board/src/main/java/com/example/springboard/domain/comment/service/CommentService.java @@ -33,7 +33,8 @@ public List getComments(Long postId, Integer page, Integer count) public void addComment(Long postId, Long memberId, String content, Float score) { Comment comment = Comment.createComment(memberId, postId, content, score); - if(commentRepository.insertComment(comment) == false) { + boolean result = commentRepository.insertComment(comment); + if(!result) { throw new RuntimeException("삽입에 실패 했습니다."); } } diff --git a/spring-board/src/main/java/com/example/springboard/domain/post/repository/PostRedisDao.java b/spring-board/src/main/java/com/example/springboard/domain/post/repository/PostRedisDao.java index a4ec194..7c62fac 100644 --- a/spring-board/src/main/java/com/example/springboard/domain/post/repository/PostRedisDao.java +++ b/spring-board/src/main/java/com/example/springboard/domain/post/repository/PostRedisDao.java @@ -35,11 +35,15 @@ public int increaseView(Long postId) { if(valueOperations.get(key) == null) { valueOperations.set(generateKey(postId, KeyType.REAL), postRepository.getPostById(postId).getViews()); } - valueOperations.set(generateKey(postId, KeyType.SHADOW) , "", Duration.ofSeconds(1)); + resetShadowKey(postId, valueOperations); return valueOperations.increment(key).intValue(); } + private void resetShadowKey(Long postId, ValueOperations valueOperations) { + valueOperations.set(generateKey(postId, KeyType.SHADOW) , "", Duration.ofMinutes(5)); + } + public int getViews(Long postId) { String key = generateKey(postId, KeyType.REAL); return (int) redisTemplate.opsForValue().get(key); diff --git a/spring-board/src/main/java/com/example/springboard/domain/post/service/PostService.java b/spring-board/src/main/java/com/example/springboard/domain/post/service/PostService.java index f4e54a6..2d862d1 100644 --- a/spring-board/src/main/java/com/example/springboard/domain/post/service/PostService.java +++ b/spring-board/src/main/java/com/example/springboard/domain/post/service/PostService.java @@ -53,7 +53,8 @@ public void editPost(Long postId, Long memberId, String title, String content) { public void deletePost(Long postId, Long memberId) { checkAuth(postId, memberId); - postRedisDao.deleteAndGet(postId); + int views = postRedisDao.deleteAndGet(postId); + postRepository.updateViews(postId, views); postRepository.deletePost(postId); }