perf(消息通知): 优化发送通知的性能

This commit is contained in:
CaptainB 2022-03-11 14:00:10 +08:00 committed by 刘瑞斌
parent bf0f33f110
commit 038a26a7cc
4 changed files with 4 additions and 7 deletions

View File

@ -9,7 +9,6 @@ import io.metersphere.notice.service.NoticeSendService;
import io.metersphere.service.SystemParameterService; import io.metersphere.service.SystemParameterService;
import org.apache.commons.beanutils.BeanMap; import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -25,7 +24,6 @@ public class AfterReturningNoticeSendService {
@Resource @Resource
private NoticeSendService noticeSendService; private NoticeSendService noticeSendService;
@Async
public void sendNotice(SendNotice sendNotice, Object retValue, SessionUser sessionUser, String currentProjectId) { public void sendNotice(SendNotice sendNotice, Object retValue, SessionUser sessionUser, String currentProjectId) {
// //
List<Map> resources = new ArrayList<>(); List<Map> resources = new ArrayList<>();

View File

@ -1,9 +1,7 @@
package io.metersphere.notice.sender; package io.metersphere.notice.sender;
import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.MessageDetail;
import org.springframework.scheduling.annotation.Async;
public interface NoticeSender { public interface NoticeSender {
@Async
void send(MessageDetail messageDetail, NoticeModel noticeModel); void send(MessageDetail messageDetail, NoticeModel noticeModel);
} }

View File

@ -9,6 +9,7 @@ import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.sender.impl.*; import io.metersphere.notice.sender.impl.*;
import org.apache.commons.lang3.SerializationUtils; import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -59,6 +60,7 @@ public class NoticeSendService {
/** /**
* 在线操作发送通知 * 在线操作发送通知
*/ */
@Async
public void send(String taskType, NoticeModel noticeModel) { public void send(String taskType, NoticeModel noticeModel) {
try { try {
String projectId = (String) noticeModel.getParamMap().get("projectId"); String projectId = (String) noticeModel.getParamMap().get("projectId");
@ -81,6 +83,7 @@ public class NoticeSendService {
/** /**
* jenkins 和定时任务触发的发送 * jenkins 和定时任务触发的发送
*/ */
@Async
public void send(String triggerMode, String taskType, NoticeModel noticeModel) { public void send(String triggerMode, String taskType, NoticeModel noticeModel) {
// api和定时任务调用不排除自己 // api和定时任务调用不排除自己
noticeModel.setExcludeSelf(false); noticeModel.setExcludeSelf(false);
@ -119,6 +122,7 @@ public class NoticeSendService {
/** /**
* 后台触发的发送没有session * 后台触发的发送没有session
*/ */
@Async
public void send(Project project, String taskType, NoticeModel noticeModel) { public void send(Project project, String taskType, NoticeModel noticeModel) {
try { try {
List<MessageDetail> messageDetails; List<MessageDetail> messageDetails;

View File

@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.MessageTask; import io.metersphere.base.domain.MessageTask;
import io.metersphere.base.domain.MessageTaskExample; import io.metersphere.base.domain.MessageTaskExample;
import io.metersphere.base.mapper.MessageTaskMapper; import io.metersphere.base.mapper.MessageTaskMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
@ -29,8 +28,6 @@ import java.util.stream.Collectors;
public class NoticeService { public class NoticeService {
@Resource @Resource
private MessageTaskMapper messageTaskMapper; private MessageTaskMapper messageTaskMapper;
@Resource
private ProjectMapper projectMapper;
public void saveMessageTask(MessageDetail messageDetail) { public void saveMessageTask(MessageDetail messageDetail) {
MessageTaskExample example = new MessageTaskExample(); MessageTaskExample example = new MessageTaskExample();