fix: verify query params to avoid invalid queries (#77)

This commit is contained in:
Fine0830 2022-05-05 19:12:32 +08:00 committed by GitHub
parent 7d1bb43adb
commit 2a2500a28d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -85,6 +85,9 @@ export const ebpfStore = defineStore({
return res.data; return res.data;
}, },
async getTaskList(serviceId: string) { async getTaskList(serviceId: string) {
if (!serviceId) {
return new Promise((resolve) => resolve({}));
}
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
.query("getEBPFTasks") .query("getEBPFTasks")
.params({ serviceId }); .params({ serviceId });
@ -101,6 +104,9 @@ export const ebpfStore = defineStore({
return res.data; return res.data;
}, },
async getEBPFSchedules(params: { taskId: string; duration?: Duration }) { async getEBPFSchedules(params: { taskId: string; duration?: Duration }) {
if (!params.taskId) {
return new Promise((resolve) => resolve({}));
}
const duration = useAppStoreWithOut().durationTime; const duration = useAppStoreWithOut().durationTime;
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
.query("getEBPFSchedules") .query("getEBPFSchedules")
@ -124,6 +130,12 @@ export const ebpfStore = defineStore({
scheduleIdList: string[]; scheduleIdList: string[];
timeRanges: Array<{ start: number; end: number }>; timeRanges: Array<{ start: number; end: number }>;
}) { }) {
if (!params.scheduleIdList.length) {
return new Promise((resolve) => resolve({}));
}
if (!params.timeRanges.length) {
return new Promise((resolve) => resolve({}));
}
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
.query("getEBPFResult") .query("getEBPFResult")
.params(params); .params(params);

View File

@ -122,6 +122,9 @@ export const profileStore = defineStore({
return res.data; return res.data;
}, },
async getSegmentList(params: { taskID: string }) { async getSegmentList(params: { taskID: string }) {
if (!params.taskID) {
return new Promise((resolve) => resolve({}));
}
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
.query("getProfileTaskSegmentList") .query("getProfileTaskSegmentList")
.params(params); .params(params);
@ -148,6 +151,9 @@ export const profileStore = defineStore({
return res.data; return res.data;
}, },
async getSegmentSpans(params: { segmentId: string }) { async getSegmentSpans(params: { segmentId: string }) {
if (!params.segmentId) {
return new Promise((resolve) => resolve({}));
}
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
.query("queryProfileSegment") .query("queryProfileSegment")
.params(params); .params(params);
@ -180,6 +186,12 @@ export const profileStore = defineStore({
segmentId: string; segmentId: string;
timeRanges: Array<{ start: number; end: number }>; timeRanges: Array<{ start: number; end: number }>;
}) { }) {
if (!params.segmentId) {
return new Promise((resolve) => resolve({}));
}
if (!params.timeRanges.length) {
return new Promise((resolve) => resolve({}));
}
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
.query("getProfileAnalyze") .query("getProfileAnalyze")
.params(params); .params(params);

View File

@ -140,6 +140,7 @@ const selectedTask = ref<TaskListItem | Record<string, never>>({});
const instanceLogs = ref<TaskLog | any>({}); const instanceLogs = ref<TaskLog | any>({});
async function changeTask(item: TaskListItem) { async function changeTask(item: TaskListItem) {
profileStore.setCurrentSegment({});
selectedTask.value = item; selectedTask.value = item;
const res = await profileStore.getSegmentList({ taskID: item.id }); const res = await profileStore.getSegmentList({ taskID: item.id });
if (res.errors) { if (res.errors) {