Skip to content

Commit

Permalink
fix: incorrect number of children comment. (#1332)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Mar 28, 2021
1 parent f9a629c commit 602f170
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,22 @@ List<COMMENT> findAllByStatusAndParentIdIn(@NonNull CommentStatus status,
@NonNull
List<CommentChildrenCountProjection> findDirectChildrenCount(
@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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public Page<CommentWithHasChildrenVO> pageTopCommentsBy(@NonNull Integer targetI

// Get direct children count
List<CommentChildrenCountProjection> directChildrenCount =
baseCommentRepository.findDirectChildrenCount(topCommentIds);
baseCommentRepository.findDirectChildrenCount(topCommentIds, CommentStatus.PUBLISHED);

// Convert to comment - children count map
Map<Long, Long> commentChildrenCountMap = ServiceUtils
Expand Down

0 comments on commit 602f170

Please sign in to comment.