feat: 处理添加评论偶现失败的问题

This commit is contained in:
tim
2025-08-03 20:10:14 +08:00
parent 3a0cea8cd4
commit d70433ff93

View File

@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@@ -35,6 +36,7 @@ public class CommentService {
private final NotificationRepository notificationRepository; private final NotificationRepository notificationRepository;
private final ImageUploader imageUploader; private final ImageUploader imageUploader;
@Transactional
public Comment addComment(String username, Long postId, String content) { public Comment addComment(String username, Long postId, String content) {
long recent = commentRepository.countByAuthorAfter(username, long recent = commentRepository.countByAuthorAfter(username,
java.time.LocalDateTime.now().minusMinutes(1)); java.time.LocalDateTime.now().minusMinutes(1));