perf(接口测试): 引用关系图查询 SQL 优化

This commit is contained in:
fit2-zhao 2024-12-23 10:26:14 +08:00 committed by Craftsman
parent c0660e8827
commit 1bfa2afbcb
2 changed files with 10 additions and 4 deletions

View File

@ -3,15 +3,19 @@
<mapper namespace="io.metersphere.base.mapper.ext.BaseRelationshipEdgeMapper">
<select id="getGraphIdsByNodeIds" resultType="java.lang.String">
select distinct graph_id
select graph_id
from relationship_edge
where source_id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
or target_id in
union
select graph_id
from relationship_edge
where target_id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
</mapper>

View File

@ -293,9 +293,11 @@ public class RelationshipEdgeService {
if (CollectionUtils.isEmpty(graphIds)) {
return new ArrayList<>();
}
RelationshipEdgeExample example = new RelationshipEdgeExample();
example.createCriteria()
.andGraphIdIn(graphIds);
.andGraphIdIn(graphIds.stream()
.distinct().collect(Collectors.toList()));
return relationshipEdgeMapper.selectByExample(example);
}
@ -319,7 +321,7 @@ public class RelationshipEdgeService {
markSet.add(id);
visitedSet.add(id);
ArrayList<String> nextLevelNodes = new ArrayList();
ArrayList<String> nextLevelNodes = new ArrayList<>();
for (RelationshipEdge relationshipEdge : edges) {
if (id.equals(relationshipEdge.getSourceId())) {
nextLevelNodes.add(relationshipEdge.getTargetId());