mirror of
https://gitee.com/huoyo/ko-time.git
synced 2025-12-06 16:58:26 +08:00
optimize database saver
This commit is contained in:
parent
ceba4430d8
commit
e671f2efe6
@ -5,7 +5,7 @@ public class KoSqlConstant {
|
||||
public final static String queryMethod = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE id=?";
|
||||
public final static String queryMethodExist = "SELECT id FROM ko_method_node WHERE id=?";
|
||||
public final static String queryMethodLikeName = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE name like ?";
|
||||
public final static String queryController = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE method_type=?";
|
||||
public final static String queryMethodByType = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE method_type=?";
|
||||
public final static String updateMethod = "UPDATE ko_method_node SET name=?, class_name=?, method_name=?, route_name=?, method_type=? WHERE id=?";
|
||||
public final static String addException = "INSERT INTO ko_exception_node(id, name, class_name) VALUES (?, ?, ?)";
|
||||
public final static String queryExceptions = "SELECT id, name, class_name FROM ko_exception_node";
|
||||
@ -25,4 +25,20 @@ public class KoSqlConstant {
|
||||
public final static String queryParamsAnaBySource = "SELECT source_id, params, avg_run_time, max_run_time, min_run_time FROM ko_param_ana WHERE source_id=?";
|
||||
public final static String updateParamsAna = "UPDATE ko_param_ana SET avg_run_time=?, max_run_time=?, min_run_time=? WHERE source_id=? and params=?";
|
||||
|
||||
|
||||
public final static String queryControllers = "select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time " +
|
||||
"from ko_method_node m " +
|
||||
"join ko_method_relation r on m.id = r.target_id " +
|
||||
"where m.method_type='Controller'";
|
||||
|
||||
public final static String searchMethodsByName = "select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time " +
|
||||
"from ko_method_node m " +
|
||||
"join ko_method_relation r on m.id = r.target_id " +
|
||||
"where m.name like ?";
|
||||
|
||||
public final static String queryChildrenByParent ="select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time " +
|
||||
"from ko_method_node m " +
|
||||
"join ko_method_relation r on m.id = r.target_id " +
|
||||
"where r.source_id=?";
|
||||
|
||||
}
|
||||
|
||||
@ -342,30 +342,7 @@ public class DataBase implements GraphService {
|
||||
|
||||
@Override
|
||||
public List<MethodInfo> getControllers() {
|
||||
List<MethodInfo> methodInfos = new ArrayList<>();
|
||||
List<MethodInfo> controllers = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryController, new Object[]{MethodType.Controller.name()}, MethodInfo.class);
|
||||
for (MethodInfo methodNode : controllers) {
|
||||
String id = methodNode.getId();
|
||||
List<MethodRelation> relations = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethodReByTarget, new Object[]{id}, MethodRelation.class);
|
||||
if (relations.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
MethodRelation relation = relations.get(0);
|
||||
MethodInfo methodInfo = new MethodInfo();
|
||||
methodInfo.setId(methodNode.getId());
|
||||
methodInfo.setName(methodNode.getName());
|
||||
methodInfo.setClassName(methodNode.getClassName());
|
||||
methodInfo.setMethodName(methodNode.getMethodName());
|
||||
methodInfo.setMethodType(methodNode.getMethodType());
|
||||
methodInfo.setRouteName(methodNode.getRouteName());
|
||||
methodInfo.setValue(relation.getAvgRunTime());
|
||||
methodInfo.setAvgRunTime(relation.getAvgRunTime());
|
||||
methodInfo.setMaxRunTime(relation.getMaxRunTime());
|
||||
methodInfo.setMinRunTime(relation.getMinRunTime());
|
||||
if (!methodInfos.contains(methodInfo)) {
|
||||
methodInfos.add(methodInfo);
|
||||
}
|
||||
}
|
||||
List<MethodInfo> methodInfos = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryControllers,null,MethodInfo.class);
|
||||
return methodInfos;
|
||||
}
|
||||
|
||||
@ -381,65 +358,52 @@ public class DataBase implements GraphService {
|
||||
|
||||
@Override
|
||||
public List<MethodInfo> searchMethods(String question) {
|
||||
List<MethodInfo> methodInfos = new ArrayList<>();
|
||||
List<MethodNode> methodNodes = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethodLikeName, new Object[]{"%" + question + "%"}, MethodNode.class);
|
||||
for (MethodNode methodNode : methodNodes) {
|
||||
String id = methodNode.getId();
|
||||
List<MethodRelation> relations = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethodReByTarget, new Object[]{id}, MethodRelation.class);
|
||||
if (relations.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
MethodRelation relation = relations.get(0);
|
||||
MethodInfo methodInfo = new MethodInfo();
|
||||
methodInfo.setId(methodNode.getId());
|
||||
methodInfo.setName(methodNode.getName());
|
||||
methodInfo.setClassName(methodNode.getClassName());
|
||||
methodInfo.setMethodName(methodNode.getMethodName());
|
||||
methodInfo.setMethodType(methodNode.getMethodType());
|
||||
methodInfo.setRouteName(methodNode.getRouteName());
|
||||
methodInfo.setValue(relation.getAvgRunTime());
|
||||
methodInfo.setAvgRunTime(relation.getAvgRunTime());
|
||||
methodInfo.setMaxRunTime(relation.getMaxRunTime());
|
||||
methodInfo.setMinRunTime(relation.getMinRunTime());
|
||||
if (!methodInfos.contains(methodInfo)) {
|
||||
methodInfos.add(methodInfo);
|
||||
}
|
||||
}
|
||||
List<MethodInfo> methodInfos = DataBaseUtil.query(getReadConnection(), KoSqlConstant.searchMethodsByName,new Object[]{"%" + question + "%"},MethodInfo.class);
|
||||
return methodInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MethodInfo> getChildren(String methodId) {
|
||||
|
||||
List<MethodRelation> relations = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethodReBySource, new Object[]{methodId}, MethodRelation.class);
|
||||
|
||||
List<MethodInfo> methodInfos = new ArrayList<>();
|
||||
for (MethodRelation methodRelation : relations) {
|
||||
List<MethodNode> methodNodes = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethod, new Object[]{methodRelation.getTargetId()}, MethodNode.class);
|
||||
if (methodNodes.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
MethodNode methodNode = methodNodes.get(0);
|
||||
MethodInfo methodInfo = new MethodInfo();
|
||||
methodInfo.setId(methodNode.getId());
|
||||
methodInfo.setName(methodNode.getName());
|
||||
methodInfo.setClassName(methodNode.getClassName());
|
||||
methodInfo.setMethodName(methodNode.getMethodName());
|
||||
methodInfo.setRouteName(methodNode.getRouteName());
|
||||
methodInfo.setMethodType(methodNode.getMethodType());
|
||||
methodInfo.setValue(methodRelation.getAvgRunTime());
|
||||
methodInfo.setAvgRunTime(methodRelation.getAvgRunTime());
|
||||
methodInfo.setMaxRunTime(methodRelation.getMaxRunTime());
|
||||
methodInfo.setMinRunTime(methodRelation.getMinRunTime());
|
||||
|
||||
List<ExceptionInfo> exceptionInfos = getExceptions(methodNode.getId());
|
||||
List<MethodInfo> methodInfosResult = new ArrayList<>();
|
||||
List<MethodInfo> methodInfos = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryChildrenByParent,new Object[]{methodId},MethodInfo.class);
|
||||
for (MethodInfo methodInfo : methodInfos) {
|
||||
List<ExceptionInfo> exceptionInfos = getExceptions(methodInfo.getId());
|
||||
methodInfo.setExceptionNum(exceptionInfos.size());
|
||||
methodInfo.setExceptions(exceptionInfos);
|
||||
if (!methodInfos.contains(methodInfo)) {
|
||||
methodInfos.add(methodInfo);
|
||||
if (!methodInfosResult.contains(methodInfo)) {
|
||||
methodInfosResult.add(methodInfo);
|
||||
}
|
||||
}
|
||||
return methodInfos;
|
||||
return methodInfosResult;
|
||||
|
||||
// List<MethodRelation> relations = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethodReBySource, new Object[]{methodId}, MethodRelation.class);
|
||||
//
|
||||
// for (MethodRelation methodRelation : relations) {
|
||||
// List<MethodNode> methodNodes = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethod, new Object[]{methodRelation.getTargetId()}, MethodNode.class);
|
||||
// if (methodNodes.size() == 0) {
|
||||
// continue;
|
||||
// }
|
||||
// MethodNode methodNode = methodNodes.get(0);
|
||||
// MethodInfo methodInfo = new MethodInfo();
|
||||
// methodInfo.setId(methodNode.getId());
|
||||
// methodInfo.setName(methodNode.getName());
|
||||
// methodInfo.setClassName(methodNode.getClassName());
|
||||
// methodInfo.setMethodName(methodNode.getMethodName());
|
||||
// methodInfo.setRouteName(methodNode.getRouteName());
|
||||
// methodInfo.setMethodType(methodNode.getMethodType());
|
||||
// methodInfo.setValue(methodRelation.getAvgRunTime());
|
||||
// methodInfo.setAvgRunTime(methodRelation.getAvgRunTime());
|
||||
// methodInfo.setMaxRunTime(methodRelation.getMaxRunTime());
|
||||
// methodInfo.setMinRunTime(methodRelation.getMinRunTime());
|
||||
//
|
||||
// List<ExceptionInfo> exceptionInfos = getExceptions(methodNode.getId());
|
||||
// methodInfo.setExceptionNum(exceptionInfos.size());
|
||||
// methodInfo.setExceptions(exceptionInfos);
|
||||
// if (!methodInfos.contains(methodInfo)) {
|
||||
// methodInfos.add(methodInfo);
|
||||
// }
|
||||
// }
|
||||
// return methodInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user