From 15d2f8e56c9f103b74dabd4e40776b940386668c Mon Sep 17 00:00:00 2001 From: John Niang Date: Fri, 6 May 2022 13:08:13 +0800 Subject: [PATCH] Set transaction isolation to read_uncommitted due to @Async (#1916) * Set transaction isolation to read_uncommitted due to @Async Comment events handlers are executed asynchronously. And default transaction isolation is read_committed, so the handlers can not see the comments created by event dispatcher Signed-off-by: johnniang * Use @TransactionalEventListener instead Signed-off-by: johnniang --- .../halo/app/listener/comment/CommentEventListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/run/halo/app/listener/comment/CommentEventListener.java b/src/main/java/run/halo/app/listener/comment/CommentEventListener.java index bba9913b8..779233afb 100644 --- a/src/main/java/run/halo/app/listener/comment/CommentEventListener.java +++ b/src/main/java/run/halo/app/listener/comment/CommentEventListener.java @@ -4,9 +4,9 @@ import java.util.HashMap; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import org.springframework.transaction.event.TransactionalEventListener; import run.halo.app.event.comment.CommentNewEvent; import run.halo.app.event.comment.CommentReplyEvent; import run.halo.app.exception.ServiceException; @@ -88,12 +88,12 @@ public class CommentEventListener { } /** - * Received a new new comment event. + * Received a new comment event. * * @param newEvent new comment event. */ @Async - @EventListener + @TransactionalEventListener public void handleCommentNewEvent(CommentNewEvent newEvent) { Boolean newCommentNotice = optionService .getByPropertyOrDefault(CommentProperties.NEW_NOTICE, Boolean.class, false); @@ -181,7 +181,7 @@ public class CommentEventListener { * @param replyEvent reply comment event. */ @Async - @EventListener + @TransactionalEventListener public void handleCommentReplyEvent(CommentReplyEvent replyEvent) { Boolean replyCommentNotice = optionService .getByPropertyOrDefault(CommentProperties.REPLY_NOTICE, Boolean.class, false);