Fix comment count bug

pull/172/head
johnniang 2019-05-31 15:08:55 +08:00
parent 5c4ace9bc9
commit 73c6f75469
4 changed files with 59 additions and 14 deletions

View File

@ -50,7 +50,7 @@ public class JournalController {
}
@GetMapping
@ApiOperation("Gets latest journals")
@ApiOperation("Lists journals")
public Page<JournalWithCmtCountDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
JournalQuery journalQuery) {
Page<Journal> journalPage = journalService.pageBy(journalQuery, pageable);

View File

@ -1,8 +1,14 @@
package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.JournalComment;
import run.halo.app.model.projection.CommentChildrenCountProjection;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository;
import java.util.List;
/**
* Journal comment repository.
*
@ -11,8 +17,18 @@ import run.halo.app.repository.base.BaseCommentRepository;
*/
public interface JournalCommentRepository extends BaseCommentRepository<JournalComment> {
// @Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) from JournalComment comment where comment.postId in ?1 group by comment.postId")
// @NonNull
// @Override
// List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
@Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) " +
"from JournalComment comment " +
"where comment.postId in ?1 group by comment.postId")
@NonNull
@Override
List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
@Query("select new run.halo.app.model.projection.CommentChildrenCountProjection(count(comment.id), comment.parentId) " +
"from JournalComment comment " +
"where comment.parentId in ?1 " +
"group by comment.parentId")
@NonNull
@Override
List<CommentChildrenCountProjection> findDirectChildrenCount(@NonNull Iterable<Long> commentIds);
}

View File

@ -1,8 +1,14 @@
package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.PostComment;
import run.halo.app.model.projection.CommentChildrenCountProjection;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository;
import java.util.List;
/**
* PostComment repository.
*
@ -11,9 +17,17 @@ import run.halo.app.repository.base.BaseCommentRepository;
*/
public interface PostCommentRepository extends BaseCommentRepository<PostComment> {
// @Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) from PostComment comment where comment.postId in ?1 group by comment.postId")
// @NonNull
// @Override
// List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
@Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) " +
"from PostComment comment " +
"where comment.postId in ?1 group by comment.postId")
@NonNull
@Override
List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
@Query("select new run.halo.app.model.projection.CommentChildrenCountProjection(count(comment.id), comment.parentId) " +
"from PostComment comment " +
"where comment.parentId in ?1 " +
"group by comment.parentId")
@NonNull
List<CommentChildrenCountProjection> findDirectChildrenCount(@NonNull Iterable<Long> commentIds);
}

View File

@ -1,8 +1,14 @@
package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.SheetComment;
import run.halo.app.model.projection.CommentChildrenCountProjection;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository;
import java.util.List;
/**
* Sheet comment repository.
*
@ -10,9 +16,18 @@ import run.halo.app.repository.base.BaseCommentRepository;
* @date 19-4-24
*/
public interface SheetCommentRepository extends BaseCommentRepository<SheetComment> {
//
// @Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) from SheetComment comment where comment.postId in ?1 group by comment.postId")
// @NonNull
// @Override
// List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
@Query("select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), comment.postId) " +
"from SheetComment comment " +
"where comment.postId in ?1 group by comment.postId")
@NonNull
@Override
List<CommentCountProjection> countByPostIds(@NonNull Iterable<Integer> postIds);
@Query("select new run.halo.app.model.projection.CommentChildrenCountProjection(count(comment.id), comment.parentId) " +
"from SheetComment comment " +
"where comment.parentId in ?1 " +
"group by comment.parentId")
@NonNull
List<CommentChildrenCountProjection> findDirectChildrenCount(@NonNull Iterable<Long> commentIds);
}