feat: 去除多线程操作 规避400问题

This commit is contained in:
tim
2025-08-06 01:45:46 +08:00
parent 004924815b
commit f0d1caf5f3

View File

@@ -72,7 +72,7 @@ public class NotificationService {
} }
n = notificationRepository.save(n); n = notificationRepository.save(n);
Runnable asyncTask = () -> { // Runnable asyncTask = () -> {
if (type == NotificationType.COMMENT_REPLY && user.getEmail() != null && post != null && comment != null) { if (type == NotificationType.COMMENT_REPLY && user.getEmail() != null && post != null && comment != null) {
String url = String.format("%s/posts/%d#comment-%d", websiteUrl, post.getId(), comment.getId()); String url = String.format("%s/posts/%d#comment-%d", websiteUrl, post.getId(), comment.getId());
emailSender.sendEmail(user.getEmail(), "有人回复了你", url); emailSender.sendEmail(user.getEmail(), "有人回复了你", url);
@@ -96,18 +96,18 @@ public class NotificationService {
// } // }
// } // }
} }
}; // };
if (TransactionSynchronizationManager.isSynchronizationActive()) { // if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { // TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override // @Override
public void afterCommit() { // public void afterCommit() {
notificationExecutor.execute(asyncTask); // notificationExecutor.execute(asyncTask);
} // }
}); // });
} else { // } else {
notificationExecutor.execute(asyncTask); // notificationExecutor.execute(asyncTask);
} // }
return n; return n;
} }