From 863c9d457d293742f2ce93eff9518dc587f86e33 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sun, 28 Mar 2021 20:37:02 +0800 Subject: [PATCH] fix: incorrect number of children comment. --- .../repository/base/BaseCommentRepository.java | 18 ++++++++++++++++++ .../service/impl/BaseCommentServiceImpl.java | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java b/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java index 00e99860b8..fbf3604b16 100644 --- a/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java +++ b/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java @@ -223,4 +223,22 @@ List findAllByStatusAndParentIdIn(@NonNull CommentStatus status, @NonNull List findDirectChildrenCount( @NonNull Collection commentIds); + + /** + * Finds direct children count by comment ids and status. + * + * @param commentIds comment ids must not be null. + * @param status comment status must not be null. + * @return a list of CommentChildrenCountProjection + */ + @Query( + "select new run.halo.app.model.projection.CommentChildrenCountProjection(count(comment" + + ".id), comment.parentId) " + + "from BaseComment comment " + + "where comment.parentId in ?1 " + + "and comment.status = ?2 " + + "group by comment.parentId") + @NonNull + List findDirectChildrenCount( + @NonNull Collection commentIds, @NonNull CommentStatus status); } diff --git a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java index f2c535ff36..de4be89e8b 100644 --- a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java @@ -580,7 +580,7 @@ public Page pageTopCommentsBy(@NonNull Integer targetI // Get direct children count List directChildrenCount = - baseCommentRepository.findDirectChildrenCount(topCommentIds); + baseCommentRepository.findDirectChildrenCount(topCommentIds, CommentStatus.PUBLISHED); // Convert to comment - children count map Map commentChildrenCountMap = ServiceUtils