From 816af625e4f95b6c391f43a3feda3092b66917d6 Mon Sep 17 00:00:00 2001 From: johnniang Date: Tue, 14 May 2019 23:47:06 +0800 Subject: [PATCH] Fix page top comments bug --- .../app/repository/base/BaseCommentRepository.java | 14 +++++++++++++- .../app/service/impl/BaseCommentServiceImpl.java | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) 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 4658d8386..6385adc7b 100644 --- a/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java +++ b/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java @@ -84,7 +84,7 @@ public interface BaseCommentRepository extends Base List findAllByPostIdAndStatus(Integer postId, CommentStatus status); /** - * Finds comments by post id, comment status. + * Finds comments by post id and comment status. * * @param postId post id must not be null * @param status comment status must not be null @@ -94,6 +94,18 @@ public interface BaseCommentRepository extends Base @NonNull Page findAllByPostIdAndStatus(Integer postId, CommentStatus status, Pageable pageable); + /** + * Finds comments by post id, comment status and parent id. + * + * @param postId post id must not be null + * @param status comment status must not be null + * @param parentId comment parent id must not be null + * @param pageable page info must not be null + * @return a page of comment + */ + @NonNull + Page findAllByPostIdAndStatusAndParentId(Integer postId, CommentStatus status, Long parentId, Pageable pageable); + @Query("select new run.halo.app.model.projection.CommentChildrenCountProjection(count(comment.id), comment.parentId) " + "from BaseComment comment " + "where comment.parentId in ?1 " + 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 1ce99e536..1b28d73ba 100644 --- a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java @@ -425,7 +425,7 @@ public abstract class BaseCommentServiceImpl extend Assert.notNull(pageable, "Page info must not be null"); // Get all comments - Page topCommentPage = baseCommentRepository.findAllByPostIdAndStatus(targetId, status, pageable); + Page topCommentPage = baseCommentRepository.findAllByPostIdAndStatusAndParentId(targetId, status, 0L, pageable); // Get top comment ids Set topCommentIds = ServiceUtils.fetchProperty(topCommentPage.getContent(), BaseComment::getId);