mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-06 23:21:16 +08:00
fix: 旧帖子的last_reply_at也要及时更新(仅一次)
This commit is contained in:
@@ -83,7 +83,10 @@ public class PostMapper {
|
||||
dto.setParticipants(participants.stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
||||
|
||||
LocalDateTime last = post.getLastReplyAt();
|
||||
dto.setLastReplyAt(last != null ? last : post.getCreatedAt());
|
||||
if (last == null) {
|
||||
commentService.updatePostCommentStats(post);
|
||||
}
|
||||
dto.setLastReplyAt(post.getLastReplyAt());
|
||||
dto.setReward(0);
|
||||
dto.setSubscribed(false);
|
||||
dto.setType(post.getType());
|
||||
|
||||
@@ -346,12 +346,16 @@ public class CommentService {
|
||||
/**
|
||||
* Update post comment statistics (comment count and last reply time)
|
||||
*/
|
||||
private void updatePostCommentStats(Post post) {
|
||||
public void updatePostCommentStats(Post post) {
|
||||
long commentCount = commentRepository.countByPostId(post.getId());
|
||||
LocalDateTime lastReplyAt = commentRepository.findLastCommentTime(post);
|
||||
|
||||
post.setCommentCount(commentCount);
|
||||
post.setLastReplyAt(lastReplyAt);
|
||||
|
||||
LocalDateTime lastReplyAt = commentRepository.findLastCommentTime(post);
|
||||
if (lastReplyAt == null) {
|
||||
post.setLastReplyAt(post.getCreatedAt());
|
||||
} else {
|
||||
post.setLastReplyAt(lastReplyAt);
|
||||
}
|
||||
postRepository.save(post);
|
||||
|
||||
log.debug("Updated post {} stats: commentCount={}, lastReplyAt={}",
|
||||
|
||||
Reference in New Issue
Block a user