fix comment children totalElements

main
wangqing 5 months ago
parent 848143d627
commit c830820695

@ -400,6 +400,7 @@ public class CommentController extends BaseController {
List<CommentResp> list = (List<CommentResp>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+parentId,page+"_"+size, key->getChildrenCommentList(parentId,page,size),true).getValue();
// List<CommentResp> list = getChildrenCommentList(parentId,page,size);
//验证是否登录并且拿到ID
Long count = (Long) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT,parentId, key->getChildrenCommentListCount(parentId,page,size),true).getValue();
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
@ -408,7 +409,7 @@ public class CommentController extends BaseController {
String userId = userLoginDto.getUserId();
Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet());
list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
return Result.success(new PageResult<CommentResp>(count,list));
}
@ -418,6 +419,11 @@ public class CommentController extends BaseController {
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x)).collect(Collectors.toList());
return list;
}
private Long getChildrenCommentListCount(String parentId,int page,int size) {
Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
return pageList.getTotalElements();
}
@ApiOperation(value = "点赞/取消点赞评论",notes = "返回")
@PutMapping("/thumbup/{commentId}")
public Result thumbup(@PathVariable String commentId,@RequestHeader(value = "Authorization", required = true) String authorization) {

@ -145,6 +145,7 @@ public class CommentService {
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+comment.getParentId());
cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT,comment.getParentId());
}
@ -170,6 +171,8 @@ public class CommentService {
rabbitTemplate.convertAndSend(Constants.RABBIT_MESSAGE_CLEAN_JOURANL_QUERY_PAGE,comment.getRootJournalId());
if (StringUtils.isNotEmpty(comment.getParentId())){
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+comment.getParentId());
cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT,comment.getParentId());
Query query = new Query();
query.addCriteria(Criteria.where("_id").is(comment.getRootId()));
Update update = new Update();

@ -24,6 +24,7 @@ public class Constants {
public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW = "journal_comment_page_new";
public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN = "journal_comment_page_children";
public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT = "journal_comment_page_children_count";
public static final String J2CACHE_REGION_SEARCH_AUTO_COMPLETE = "search_auto_complete";
public static final String J2CACHE_REGION_JOURNAL_HOT_COMMENTS = "journal_hot_comments";

Loading…
Cancel
Save