Skip to content

Commit

Permalink
Set transaction isolation to read_uncommitted due to @async (halo-dev…
Browse files Browse the repository at this point in the history
…#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 <[email protected]>

* Use @TransactionalEventListener instead

Signed-off-by: johnniang <[email protected]>
  • Loading branch information
JohnNiang authored May 6, 2022
1 parent bca4e53 commit 15d2f8e
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
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;
Expand Down Expand Up @@ -88,12 +88,12 @@ public CommentEventListener(MailService mailService, OptionService optionService
}

/**
* 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);
Expand Down Expand Up @@ -181,7 +181,7 @@ public void handleCommentNewEvent(CommentNewEvent newEvent) {
* @param replyEvent reply comment event.
*/
@Async
@EventListener
@TransactionalEventListener
public void handleCommentReplyEvent(CommentReplyEvent replyEvent) {
Boolean replyCommentNotice = optionService
.getByPropertyOrDefault(CommentProperties.REPLY_NOTICE, Boolean.class, false);
Expand Down

0 comments on commit 15d2f8e

Please sign in to comment.