mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-07-20 03:26:18 +00: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()));
|
dto.setParticipants(participants.stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
||||||
|
|
||||||
LocalDateTime last = post.getLastReplyAt();
|
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.setReward(0);
|
||||||
dto.setSubscribed(false);
|
dto.setSubscribed(false);
|
||||||
dto.setType(post.getType());
|
dto.setType(post.getType());
|
||||||
|
|||||||
@@ -346,12 +346,16 @@ public class CommentService {
|
|||||||
/**
|
/**
|
||||||
* Update post comment statistics (comment count and last reply time)
|
* 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());
|
long commentCount = commentRepository.countByPostId(post.getId());
|
||||||
LocalDateTime lastReplyAt = commentRepository.findLastCommentTime(post);
|
|
||||||
|
|
||||||
post.setCommentCount(commentCount);
|
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);
|
postRepository.save(post);
|
||||||
|
|
||||||
log.debug("Updated post {} stats: commentCount={}, lastReplyAt={}",
|
log.debug("Updated post {} stats: commentCount={}, lastReplyAt={}",
|
||||||
|
|||||||
Reference in New Issue
Block a user