mirror of https://github.com/halo-dev/halo
Fix issue#177
parent
4f15e8bf1e
commit
9b92867ea3
|
@ -429,6 +429,11 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
||||||
// Get all comments
|
// Get all comments
|
||||||
Page<COMMENT> topCommentPage = baseCommentRepository.findAllByPostIdAndStatusAndParentId(targetId, status, 0L, pageable);
|
Page<COMMENT> topCommentPage = baseCommentRepository.findAllByPostIdAndStatusAndParentId(targetId, status, 0L, pageable);
|
||||||
|
|
||||||
|
if (topCommentPage.isEmpty()) {
|
||||||
|
// If the comments is empty
|
||||||
|
return ServiceUtils.buildEmptyPageImpl(topCommentPage);
|
||||||
|
}
|
||||||
|
|
||||||
// Get top comment ids
|
// Get top comment ids
|
||||||
Set<Long> topCommentIds = ServiceUtils.fetchProperty(topCommentPage.getContent(), BaseComment::getId);
|
Set<Long> topCommentIds = ServiceUtils.fetchProperty(topCommentPage.getContent(), BaseComment::getId);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package run.halo.app.utils;
|
package run.halo.app.utils;
|
||||||
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.*;
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
@ -136,6 +134,21 @@ public class ServiceUtils {
|
||||||
return buildLatestPageable(top, "createTime");
|
return buildLatestPageable(top, "createTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build empty page result.
|
||||||
|
*
|
||||||
|
* @param page page info must not be null
|
||||||
|
* @param <T> target page result type
|
||||||
|
* @param <S> source page result type
|
||||||
|
* @return empty page result
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public static <T, S> Page<T> buildEmptyPageImpl(@NonNull Page<S> page) {
|
||||||
|
Assert.notNull(page, "Page result must not be null");
|
||||||
|
|
||||||
|
return new PageImpl<>(Collections.emptyList(), page.getPageable(), page.getTotalElements());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds latest page request.
|
* Builds latest page request.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue