mirror of https://github.com/halo-dev/halo
🐛 修复删除文章或者评论后出现的异常
parent
5add534464
commit
006d538f22
|
@ -24,6 +24,8 @@ public class CommentServiceImpl implements CommentService {
|
||||||
|
|
||||||
private static final String COMMENTS_CACHE_NAME = "comments";
|
private static final String COMMENTS_CACHE_NAME = "comments";
|
||||||
|
|
||||||
|
private static final String POSTS_CACHE_NAME = "posts";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommentRepository commentRepository;
|
private CommentRepository commentRepository;
|
||||||
|
|
||||||
|
@ -33,7 +35,7 @@ public class CommentServiceImpl implements CommentService {
|
||||||
* @param comment comment
|
* @param comment comment
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = {COMMENTS_CACHE_NAME, POSTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||||
public void saveByComment(Comment comment) {
|
public void saveByComment(Comment comment) {
|
||||||
commentRepository.save(comment);
|
commentRepository.save(comment);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +47,7 @@ public class CommentServiceImpl implements CommentService {
|
||||||
* @return Optional
|
* @return Optional
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = {COMMENTS_CACHE_NAME, POSTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||||
public Optional<Comment> removeByCommentId(Long commentId) {
|
public Optional<Comment> removeByCommentId(Long commentId) {
|
||||||
Optional<Comment> comment = this.findCommentById(commentId);
|
Optional<Comment> comment = this.findCommentById(commentId);
|
||||||
commentRepository.delete(comment.get());
|
commentRepository.delete(comment.get());
|
||||||
|
|
|
@ -32,6 +32,8 @@ public class PostServiceImpl implements PostService {
|
||||||
|
|
||||||
private static final String POSTS_CACHE_NAME = "posts";
|
private static final String POSTS_CACHE_NAME = "posts";
|
||||||
|
|
||||||
|
private static final String COMMENTS_CACHE_NAME = "comments";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PostRepository postRepository;
|
private PostRepository postRepository;
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ public class PostServiceImpl implements PostService {
|
||||||
* @return Post
|
* @return Post
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = {POSTS_CACHE_NAME, COMMENTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||||
public Post saveByPost(Post post) {
|
public Post saveByPost(Post post) {
|
||||||
return postRepository.save(post);
|
return postRepository.save(post);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +56,7 @@ public class PostServiceImpl implements PostService {
|
||||||
* @return Post
|
* @return Post
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
@CacheEvict(value = {POSTS_CACHE_NAME, COMMENTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||||
public Post removeByPostId(Long postId) {
|
public Post removeByPostId(Long postId) {
|
||||||
Optional<Post> post = this.findByPostId(postId);
|
Optional<Post> post = this.findByPostId(postId);
|
||||||
postRepository.delete(post.get());
|
postRepository.delete(post.get());
|
||||||
|
|
Loading…
Reference in New Issue