fix: 旧帖子的last_reply_at也要及时更新(仅一次)

This commit is contained in:
Tim
2025-09-17 14:14:55 +08:00
parent 9306e35b84
commit f67e220894
2 changed files with 12 additions and 5 deletions

View File

@@ -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={}",