mirror of https://github.com/halo-dev/halo
parent
8472a7b3d5
commit
f0ba0fa606
|
@ -73,6 +73,24 @@ public interface BaseCommentRepository<COMMENT extends BaseComment>
|
|||
@NonNull
|
||||
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 postIds 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 BaseComment comment "
|
||||
+ "where comment.status = ?1 "
|
||||
+ "and comment.postId in ?2 "
|
||||
+ "group by comment.postId")
|
||||
@NonNull
|
||||
List<CommentCountProjection> countByStatusAndPostIds(@NonNull CommentStatus status,
|
||||
@NonNull Collection<Integer> postIds);
|
||||
|
||||
/**
|
||||
* Count comments by post id.
|
||||
*
|
||||
|
|
|
@ -134,6 +134,16 @@ public interface BaseCommentService<COMMENT extends BaseComment>
|
|||
@NonNull
|
||||
Map<Integer, Long> countByPostIds(@Nullable Collection<Integer> postIds);
|
||||
|
||||
/**
|
||||
* Counts by comment status and post id collection.
|
||||
*
|
||||
* @param status status
|
||||
* @param postIds post id collection
|
||||
* @return a count map, key: post id, value: comment count
|
||||
*/
|
||||
Map<Integer, Long> countByStatusAndPostIds(@NonNull CommentStatus status,
|
||||
@NonNull Collection<Integer> postIds);
|
||||
|
||||
/**
|
||||
* Count comments by post id.
|
||||
*
|
||||
|
|
|
@ -253,6 +253,21 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment>
|
|||
CommentCountProjection::getCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Long> countByStatusAndPostIds(@NonNull CommentStatus status,
|
||||
@NonNull Collection<Integer> postIds) {
|
||||
if (CollectionUtils.isEmpty(postIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// Get all comment counts
|
||||
List<CommentCountProjection> commentCountProjections =
|
||||
baseCommentRepository.countByStatusAndPostIds(status, postIds);
|
||||
|
||||
return ServiceUtils.convertToMap(commentCountProjections, CommentCountProjection::getPostId,
|
||||
CommentCountProjection::getCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByPostId(Integer postId) {
|
||||
Assert.notNull(postId, "Post id must not be null");
|
||||
|
@ -444,7 +459,7 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment>
|
|||
protected Specification<COMMENT> buildSpecByQuery(@NonNull CommentQuery commentQuery) {
|
||||
Assert.notNull(commentQuery, "Comment query must not be null");
|
||||
|
||||
return (Specification<COMMENT>) (root, query, criteriaBuilder) -> {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new LinkedList<>();
|
||||
|
||||
if (commentQuery.getStatus() != null) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import run.halo.app.model.dto.JournalDTO;
|
|||
import run.halo.app.model.dto.JournalWithCmtCountDTO;
|
||||
import run.halo.app.model.entity.Journal;
|
||||
import run.halo.app.model.entity.JournalComment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import run.halo.app.model.enums.JournalType;
|
||||
import run.halo.app.model.params.JournalParam;
|
||||
import run.halo.app.model.params.JournalQuery;
|
||||
|
@ -123,7 +124,7 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer>
|
|||
|
||||
// Get comment count map
|
||||
Map<Integer, Long> journalCommentCountMap =
|
||||
journalCommentService.countByPostIds(journalIds);
|
||||
journalCommentService.countByStatusAndPostIds(CommentStatus.PUBLISHED, journalIds);
|
||||
|
||||
return journals.stream()
|
||||
.map(journal -> {
|
||||
|
@ -182,7 +183,7 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer>
|
|||
private Specification<Journal> buildSpecByQuery(@NonNull JournalQuery journalQuery) {
|
||||
Assert.notNull(journalQuery, "Journal query must not be null");
|
||||
|
||||
return (Specification<Journal>) (root, query, criteriaBuilder) -> {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new LinkedList<>();
|
||||
|
||||
if (journalQuery.getType() != null) {
|
||||
|
|
|
@ -48,6 +48,7 @@ import run.halo.app.model.entity.PostComment;
|
|||
import run.halo.app.model.entity.PostMeta;
|
||||
import run.halo.app.model.entity.PostTag;
|
||||
import run.halo.app.model.entity.Tag;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.model.enums.PostPermalinkType;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
|
@ -583,7 +584,8 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
.listCategoryListMap(postIds, queryEncryptCategory);
|
||||
|
||||
// Get comment count
|
||||
Map<Integer, Long> commentCountMap = postCommentService.countByPostIds(postIds);
|
||||
Map<Integer, Long> commentCountMap = postCommentService.countByStatusAndPostIds(
|
||||
CommentStatus.PUBLISHED, postIds);
|
||||
|
||||
// Get post meta list map
|
||||
Map<Integer, List<PostMeta>> postMetaListMap = postMetaService.listPostMetaAsMap(postIds);
|
||||
|
@ -646,7 +648,8 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
.listCategoryListMap(postIds, queryEncryptCategory);
|
||||
|
||||
// Get comment count
|
||||
Map<Integer, Long> commentCountMap = postCommentService.countByPostIds(postIds);
|
||||
Map<Integer, Long> commentCountMap =
|
||||
postCommentService.countByStatusAndPostIds(CommentStatus.PUBLISHED, postIds);
|
||||
|
||||
// Get post meta list map
|
||||
Map<Integer, List<PostMeta>> postMetaListMap = postMetaService.listPostMetaAsMap(postIds);
|
||||
|
@ -782,7 +785,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
private Specification<Post> buildSpecByQuery(@NonNull PostQuery postQuery) {
|
||||
Assert.notNull(postQuery, "Post query must not be null");
|
||||
|
||||
return (Specification<Post>) (root, query, criteriaBuilder) -> {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new LinkedList<>();
|
||||
|
||||
if (postQuery.getStatus() != null) {
|
||||
|
@ -823,15 +826,15 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
|
||||
// Create or update post
|
||||
Boolean needEncrypt = Optional.ofNullable(categoryIds)
|
||||
.filter(CollectionUtil::isNotEmpty)
|
||||
.map(categoryIdSet -> {
|
||||
for (Integer categoryId : categoryIdSet) {
|
||||
if (categoryService.categoryHasEncrypt(categoryId)) {
|
||||
return true;
|
||||
}
|
||||
.filter(CollectionUtil::isNotEmpty)
|
||||
.map(categoryIdSet -> {
|
||||
for (Integer categoryId : categoryIdSet) {
|
||||
if (categoryService.categoryHasEncrypt(categoryId)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).orElse(Boolean.FALSE);
|
||||
}
|
||||
return false;
|
||||
}).orElse(Boolean.FALSE);
|
||||
|
||||
// if password is not empty or parent category has encrypt, change status to intimate
|
||||
if (post.getStatus() != PostStatus.DRAFT
|
||||
|
|
|
@ -27,6 +27,7 @@ import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
|||
import run.halo.app.model.entity.Sheet;
|
||||
import run.halo.app.model.entity.SheetComment;
|
||||
import run.halo.app.model.entity.SheetMeta;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.enums.SheetPermalinkType;
|
||||
|
@ -276,7 +277,8 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
Set<Integer> sheetIds = ServiceUtils.fetchProperty(sheets, Sheet::getId);
|
||||
|
||||
// key: sheet id, value: comment count
|
||||
Map<Integer, Long> sheetCommentCountMap = sheetCommentService.countByPostIds(sheetIds);
|
||||
Map<Integer, Long> sheetCommentCountMap = sheetCommentService.countByStatusAndPostIds(
|
||||
CommentStatus.PUBLISHED, sheetIds);
|
||||
|
||||
return sheetPage.map(sheet -> {
|
||||
SheetListVO sheetListVO = new SheetListVO().convertFrom(sheet);
|
||||
|
|
Loading…
Reference in New Issue