From 602f1704a1a6c3d801919c8b51bc4d5f3dc3bf10 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sun, 28 Mar 2021 22:11:34 +0800 Subject: [PATCH] fix: incorrect number of children comment. (#1332) --- .../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 00e99860b..fbf3604b1 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 @@ public interface BaseCommentRepository @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 f2c535ff3..de4be89e8 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 abstract class BaseCommentServiceImpl // Get direct children count List directChildrenCount = - baseCommentRepository.findDirectChildrenCount(topCommentIds); + baseCommentRepository.findDirectChildrenCount(topCommentIds, CommentStatus.PUBLISHED); // Convert to comment - children count map Map commentChildrenCountMap = ServiceUtils