mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-08 11:07:34 +08:00
feat: 偶现400错误,线程处理
This commit is contained in:
@@ -10,7 +10,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
+import org.springframework.transaction.support.TransactionSynchronization;
|
||||||
|
+import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -71,7 +72,7 @@ public class NotificationService {
|
|||||||
}
|
}
|
||||||
n = notificationRepository.save(n);
|
n = notificationRepository.save(n);
|
||||||
|
|
||||||
notificationExecutor.execute(() -> {
|
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);
|
||||||
@@ -95,7 +96,18 @@ public class NotificationService {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||||
|
@Override
|
||||||
|
public void afterCommit() {
|
||||||
|
notificationExecutor.execute(asyncTask);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
notificationExecutor.execute(asyncTask);
|
||||||
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user