mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-19 13:30:55 +08:00
feat(posts): 优化帖子评论统计性能
- 在 Post 模型中添加 commentCount 和 lastReplyAt 字段 - 在 CommentService 中实现更新帖子评论统计的方法 - 在 PostMapper 中使用 Post 模型中的评论统计字段 - 新增数据库迁移脚本,添加评论统计字段和索引 - 更新相关测试用例
This commit is contained in:
@@ -67,7 +67,7 @@ public class PostMapper {
|
||||
dto.setCategory(categoryMapper.toDto(post.getCategory()));
|
||||
dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList()));
|
||||
dto.setViews(post.getViews());
|
||||
dto.setCommentCount(commentService.countComments(post.getId()));
|
||||
dto.setCommentCount(post.getCommentCount());
|
||||
dto.setStatus(post.getStatus());
|
||||
dto.setPinnedAt(post.getPinnedAt());
|
||||
dto.setRssExcluded(post.getRssExcluded() == null || post.getRssExcluded());
|
||||
@@ -82,7 +82,7 @@ public class PostMapper {
|
||||
List<User> participants = commentService.getParticipants(post.getId(), 5);
|
||||
dto.setParticipants(participants.stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
||||
|
||||
LocalDateTime last = commentService.getLastCommentTime(post.getId());
|
||||
LocalDateTime last = post.getLastReplyAt();
|
||||
dto.setLastReplyAt(last != null ? last : post.getCreatedAt());
|
||||
dto.setReward(0);
|
||||
dto.setSubscribed(false);
|
||||
|
||||
Reference in New Issue
Block a user