perf(消息通知): 优化发送通知的性能
--bug=1010865 --user=刘瑞斌 【测试跟踪】批量移动功能用例耗时较长 https://www.tapd.cn/55049933/s/1114701
This commit is contained in:
parent
260cefe5f9
commit
f7d6842656
|
@ -1136,6 +1136,7 @@ public class ApiDefinitionService {
|
||||||
String context = request.getSwaggerUrl() + "导入失败";
|
String context = request.getSwaggerUrl() + "导入失败";
|
||||||
Map<String, Object> paramMap = new HashMap<>();
|
Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("url", request.getSwaggerUrl());
|
paramMap.put("url", request.getSwaggerUrl());
|
||||||
|
paramMap.put("projectId", request.getProjectId());
|
||||||
NoticeModel noticeModel = NoticeModel.builder()
|
NoticeModel noticeModel = NoticeModel.builder()
|
||||||
.operator(SessionUtils.getUserId())
|
.operator(SessionUtils.getUserId())
|
||||||
.context(context)
|
.context(context)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.notice.controller;
|
||||||
|
|
||||||
import io.metersphere.commons.constants.OperLogConstants;
|
import io.metersphere.commons.constants.OperLogConstants;
|
||||||
import io.metersphere.commons.constants.OperLogModule;
|
import io.metersphere.commons.constants.OperLogModule;
|
||||||
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.log.annotation.MsAuditLog;
|
import io.metersphere.log.annotation.MsAuditLog;
|
||||||
import io.metersphere.notice.domain.MessageDetail;
|
import io.metersphere.notice.domain.MessageDetail;
|
||||||
import io.metersphere.notice.service.NoticeService;
|
import io.metersphere.notice.service.NoticeService;
|
||||||
|
@ -24,7 +25,8 @@ public class NoticeController {
|
||||||
|
|
||||||
@GetMapping("/search/message/type/{type}")
|
@GetMapping("/search/message/type/{type}")
|
||||||
public List<MessageDetail> searchMessage(@PathVariable String type) {
|
public List<MessageDetail> searchMessage(@PathVariable String type) {
|
||||||
return noticeService.searchMessageByType(type);
|
String projectId = SessionUtils.getCurrentProjectId();
|
||||||
|
return noticeService.searchMessageByTypeAndProjectId(type, projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/search/message/{testId}")
|
@GetMapping("/search/message/{testId}")
|
||||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.notice.sender;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import io.metersphere.commons.constants.NoticeConstants;
|
import io.metersphere.commons.constants.NoticeConstants;
|
||||||
import io.metersphere.commons.user.SessionUser;
|
import io.metersphere.commons.user.SessionUser;
|
||||||
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||||
import io.metersphere.notice.annotation.SendNotice;
|
import io.metersphere.notice.annotation.SendNotice;
|
||||||
import io.metersphere.notice.service.NoticeSendService;
|
import io.metersphere.notice.service.NoticeSendService;
|
||||||
|
@ -50,6 +51,7 @@ public class AfterReturningNoticeSendService {
|
||||||
paramMap.put("url", baseSystemConfigDTO.getUrl());
|
paramMap.put("url", baseSystemConfigDTO.getUrl());
|
||||||
paramMap.put("operator", sessionUser.getName());
|
paramMap.put("operator", sessionUser.getName());
|
||||||
paramMap.putAll(resource);
|
paramMap.putAll(resource);
|
||||||
|
paramMap.putIfAbsent("projectId", SessionUtils.getCurrentProjectId());
|
||||||
// 占位符
|
// 占位符
|
||||||
handleDefaultValues(paramMap);
|
handleDefaultValues(paramMap);
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,8 @@ public class NoticeSendService {
|
||||||
*/
|
*/
|
||||||
public void send(String taskType, NoticeModel noticeModel) {
|
public void send(String taskType, NoticeModel noticeModel) {
|
||||||
try {
|
try {
|
||||||
List<MessageDetail> messageDetails = noticeService.searchMessageByType(taskType);
|
String projectId = (String) noticeModel.getParamMap().get("projectId");
|
||||||
|
List<MessageDetail> messageDetails = noticeService.searchMessageByTypeAndProjectId(taskType, projectId);
|
||||||
|
|
||||||
// 异步发送通知
|
// 异步发送通知
|
||||||
messageDetails.stream()
|
messageDetails.stream()
|
||||||
|
@ -132,7 +133,7 @@ public class NoticeSendService {
|
||||||
// default:
|
// default:
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
messageDetails = noticeService.searchMessageByTypeAndWorkspaceId(taskType, project.getWorkspaceId());
|
messageDetails = noticeService.searchMessageByTypeAndProjectId(taskType, project.getId());
|
||||||
|
|
||||||
// 异步发送通知
|
// 异步发送通知
|
||||||
messageDetails.stream()
|
messageDetails.stream()
|
||||||
|
|
|
@ -111,20 +111,9 @@ public class NoticeService {
|
||||||
return scheduleMessageTask;
|
return scheduleMessageTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MessageDetail> searchMessageByType(String type) {
|
public List<MessageDetail> searchMessageByTypeAndProjectId(String type, String projectId) {
|
||||||
try {
|
try {
|
||||||
String workspaceId = SessionUtils.getCurrentWorkspaceId();
|
return getMessageDetails(type, projectId);
|
||||||
return getMessageDetails(type, workspaceId);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtil.error(e.getMessage(), e);
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<MessageDetail> searchMessageByTypeAndWorkspaceId(String type, String workspaceId) {
|
|
||||||
try {
|
|
||||||
return getMessageDetails(type, workspaceId);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue