fix: incorrect number of children comment. (#1332)

pull/1334/head
Ryan Wang 2021-03-28 22:11:34 +08:00 committed by GitHub
parent f9a629c38f
commit 602f1704a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -223,4 +223,22 @@ public interface BaseCommentRepository<COMMENT extends BaseComment>
@NonNull @NonNull
List<CommentChildrenCountProjection> findDirectChildrenCount( List<CommentChildrenCountProjection> findDirectChildrenCount(
@NonNull Collection<Long> commentIds); @NonNull Collection<Long> 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<CommentChildrenCountProjection> findDirectChildrenCount(
@NonNull Collection<Long> commentIds, @NonNull CommentStatus status);
} }

View File

@ -580,7 +580,7 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment>
// Get direct children count // Get direct children count
List<CommentChildrenCountProjection> directChildrenCount = List<CommentChildrenCountProjection> directChildrenCount =
baseCommentRepository.findDirectChildrenCount(topCommentIds); baseCommentRepository.findDirectChildrenCount(topCommentIds, CommentStatus.PUBLISHED);
// Convert to comment - children count map // Convert to comment - children count map
Map<Long, Long> commentChildrenCountMap = ServiceUtils Map<Long, Long> commentChildrenCountMap = ServiceUtils