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

--bug=1010865 --user=刘瑞斌 【测试跟踪】批量移动功能用例耗时较长 https://www.tapd.cn/55049933/s/1114701
This commit is contained in:
CaptainB 2022-03-09 12:30:06 +08:00 committed by 刘瑞斌
parent 7f881317a8
commit 3dbc32bc21
4 changed files with 14 additions and 9 deletions

View File

@ -3,7 +3,6 @@ package io.metersphere.notice.sender;
import com.alibaba.fastjson.JSON;
import io.metersphere.commons.constants.NoticeConstants;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.notice.annotation.SendNotice;
import io.metersphere.notice.service.NoticeSendService;
@ -27,7 +26,7 @@ public class AfterReturningNoticeSendService {
private NoticeSendService noticeSendService;
@Async
public void sendNotice(SendNotice sendNotice, Object retValue, SessionUser sessionUser) {
public void sendNotice(SendNotice sendNotice, Object retValue, SessionUser sessionUser, String currentWorkspaceId) {
//
List<Map> resources = new ArrayList<>();
String source = sendNotice.source();
@ -51,7 +50,7 @@ public class AfterReturningNoticeSendService {
paramMap.put("url", baseSystemConfigDTO.getUrl());
paramMap.put("operator", sessionUser.getName());
paramMap.putAll(resource);
paramMap.putIfAbsent("projectId", SessionUtils.getCurrentProjectId());
paramMap.putIfAbsent("workspaceId", currentWorkspaceId);
// 占位符
handleDefaultValues(paramMap);

View File

@ -123,7 +123,8 @@ public class SendNoticeAspect {
context.setVariable(params[len], args[len]);
}
SessionUser sessionUser = SessionUtils.getUser();
afterReturningNoticeSendService.sendNotice(sendNotice, retValue, sessionUser);
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
afterReturningNoticeSendService.sendNotice(sendNotice, retValue, sessionUser, currentWorkspaceId);
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}

View File

@ -61,8 +61,13 @@ public class NoticeSendService {
*/
public void send(String taskType, NoticeModel noticeModel) {
try {
String projectId = (String) noticeModel.getParamMap().get("projectId");
List<MessageDetail> messageDetails = noticeService.searchMessageByTypeAndProjectId(taskType, projectId);
String workspaceId = (String) noticeModel.getParamMap().get("workspaceId");
List<MessageDetail> messageDetails;
if (StringUtils.isEmpty(workspaceId)) {
messageDetails = noticeService.searchMessageByType(taskType);
} else {
messageDetails = noticeService.searchMessageByTypeAndWorkspaceId(taskType, workspaceId);
}
// 异步发送通知
messageDetails.stream()
@ -133,7 +138,7 @@ public class NoticeSendService {
// default:
// break;
// }
messageDetails = noticeService.searchMessageByTypeAndProjectId(taskType, project.getId());
messageDetails = noticeService.searchMessageByTypeAndWorkspaceId(taskType, project.getId());
// 异步发送通知
messageDetails.stream()

View File

@ -121,9 +121,9 @@ public class NoticeService {
}
}
public List<MessageDetail> searchMessageByTypeAndProjectId(String type, String projectId) {
public List<MessageDetail> searchMessageByTypeAndWorkspaceId(String type, String workspaceId) {
try {
return getMessageDetails(type, projectId);
return getMessageDetails(type, workspaceId);
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
return new ArrayList<>();