修复/getApis在redis模式下很慢的问题

This commit is contained in:
yanghuadong 2023-11-17 09:10:00 +08:00
parent 5bea7867ff
commit 6a1069e62d
2 changed files with 11 additions and 4 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.iml
.idea/
rebel.xml
target/
.txlcn
*.log

View File

@ -219,12 +219,12 @@ public class RedisBase implements GraphService {
List<MethodInfo> methodInfos = new ArrayList<>(); List<MethodInfo> methodInfos = new ArrayList<>();
List<MethodNode> smethodNodes = searchList(methodPre, MethodNode.class); List<MethodNode> smethodNodes = searchList(methodPre, MethodNode.class);
List<MethodRelation> methodRelations = searchList(methodRelationPre, MethodRelation.class);
Map<String, MethodRelation> methodRelationMap = methodRelations.stream().collect(Collectors.toMap(k -> k.getTargetId(), v -> v, (p1, p2) -> p1));
for (MethodNode methodNode : smethodNodes) { for (MethodNode methodNode : smethodNodes) {
if (MethodType.Controller == methodNode.getMethodType()) { if (MethodType.Controller == methodNode.getMethodType()) {
String id = methodNode.getId(); String id = methodNode.getId();
List<MethodRelation> smethodRelations = searchList(methodRelationPre, MethodRelation.class); Optional<MethodRelation> relations = Optional.ofNullable(methodRelationMap.get(id));
Optional<MethodRelation> relations = smethodRelations.stream().filter(methodRelation -> methodRelation.getTargetId().equals(id)).findFirst();
MethodRelation relation = null; MethodRelation relation = null;
if (relations.isPresent()) { if (relations.isPresent()) {
relation = relations.get(); relation = relations.get();
@ -266,10 +266,11 @@ public class RedisBase implements GraphService {
List<MethodInfo> methodInfos = new ArrayList<>(); List<MethodInfo> methodInfos = new ArrayList<>();
List<MethodNode> smethodNodes = searchList(methodPre, MethodNode.class); List<MethodNode> smethodNodes = searchList(methodPre, MethodNode.class);
List<MethodRelation> methodRelationList = searchList(methodRelationPre, MethodRelation.class); List<MethodRelation> methodRelationList = searchList(methodRelationPre, MethodRelation.class);
Map<String, MethodRelation> methodRelationMap = methodRelationList.stream().collect(Collectors.toMap(k -> k.getTargetId(), v -> v, (p1, p2) -> p1));
for (MethodNode methodNode : smethodNodes) { for (MethodNode methodNode : smethodNodes) {
if (methodNode.getName().toLowerCase().contains(question.toLowerCase())) { if (methodNode.getName().toLowerCase().contains(question.toLowerCase())) {
String id = methodNode.getId(); String id = methodNode.getId();
Optional<MethodRelation> relations = methodRelationList.stream().filter(methodRelation -> methodRelation.getTargetId().equals(id)).findFirst(); Optional<MethodRelation> relations = Optional.ofNullable(methodRelationMap.get(id));
MethodRelation relation = null; MethodRelation relation = null;
if (relations.isPresent()) { if (relations.isPresent()) {
relation = relations.get(); relation = relations.get();