fix: incorrect comment count statistics. #1411 (#1426)

* fix: incorrect comment count statistics. #1411

Signed-off-by: Ryan Wang <i@ryanc.cc>

* pref: add override annotation.
pull/1427/head
Ryan Wang 2021-07-18 22:08:05 +08:00 committed by GitHub
parent 95c0271cf1
commit 1e7d320f1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.JournalComment;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.projection.CommentChildrenCountProjection;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository;
@ -33,6 +34,25 @@ public interface JournalCommentRepository extends BaseCommentRepository<JournalC
@Override
List<CommentCountProjection> countByPostIds(@NonNull Collection<Integer> postIds);
/**
* Counts comment count by comment status and journal id collection.
*
* @param status status must not be null
* @param journalsId journal id collection must not be null
* @return a list of comment count
*/
@Query(
"select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), "
+ "comment.postId) "
+ "from JournalComment comment "
+ "where comment.status = ?1 "
+ "and comment.postId in ?2 "
+ "group by comment.postId")
@NonNull
@Override
List<CommentCountProjection> countByStatusAndPostIds(@NonNull CommentStatus status,
@NonNull Collection<Integer> journalsId);
/**
* Finds direct children count by comment ids.
*

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.PostComment;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.projection.CommentChildrenCountProjection;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository;
@ -34,6 +35,25 @@ public interface PostCommentRepository extends BaseCommentRepository<PostComment
@Override
List<CommentCountProjection> countByPostIds(@NonNull Collection<Integer> postIds);
/**
* Counts comment count by comment status and post id collection.
*
* @param status status must not be null
* @param postsId post id collection must not be null
* @return a list of comment count
*/
@Query(
"select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), "
+ "comment.postId) "
+ "from PostComment comment "
+ "where comment.status = ?1 "
+ "and comment.postId in ?2 "
+ "group by comment.postId")
@NonNull
@Override
List<CommentCountProjection> countByStatusAndPostIds(@NonNull CommentStatus status,
@NonNull Collection<Integer> postsId);
/**
* Finds direct children count by comment ids.
*

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.SheetComment;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.projection.CommentChildrenCountProjection;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository;
@ -33,6 +34,25 @@ public interface SheetCommentRepository extends BaseCommentRepository<SheetComme
@Override
List<CommentCountProjection> countByPostIds(@NonNull Collection<Integer> sheetIds);
/**
* Counts comment count by comment status and sheet id collection.
*
* @param status status must not be null
* @param sheetsId sheet id collection must not be null
* @return a list of comment count
*/
@Query(
"select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), "
+ "comment.postId) "
+ "from SheetComment comment "
+ "where comment.status = ?1 "
+ "and comment.postId in ?2 "
+ "group by comment.postId")
@NonNull
@Override
List<CommentCountProjection> countByStatusAndPostIds(@NonNull CommentStatus status,
@NonNull Collection<Integer> sheetsId);
/**
* Finds direct children count by comment ids.
*

View File

@ -221,6 +221,7 @@ public interface BaseCommentRepository<COMMENT extends BaseComment>
+ "where comment.parentId in ?1 "
+ "group by comment.parentId")
@NonNull
@Deprecated
List<CommentChildrenCountProjection> findDirectChildrenCount(
@NonNull Collection<Long> commentIds);