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);
Runnable asyncTask = () -> {
// Runnable asyncTask = () -> {
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());
emailSender.sendEmail(user.getEmail(), "有人回复了你", url);
@@ -96,18 +96,18 @@ public class NotificationService {
// }
// }
}
};
// };
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
notificationExecutor.execute(asyncTask);
}
});
} else {
notificationExecutor.execute(asyncTask);
}
// if (TransactionSynchronizationManager.isSynchronizationActive()) {
// TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
// @Override
// public void afterCommit() {
// notificationExecutor.execute(asyncTask);
// }
// });
// } else {
// notificationExecutor.execute(asyncTask);
// }
return n;
}