Skip to content

Commit 7bbe192

Browse files
authored
fix: Dashboard abort partition api call issue (#4430)
- #4428 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved handling of query aborting for enhanced efficiency in asynchronous operations. - **Bug Fixes** - Enhanced robustness of data conversion by implementing safer property access methods, reducing runtime errors related to undefined or null values. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 2652329 commit 7bbe192

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

web/src/composables/dashboard/usePanelDataLoader.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ export const usePanelDataLoader = (
313313
queries: queryResults.map((it: any) => it?.metadata),
314314
};
315315
} else {
316+
// copy of current abortController
317+
// which is used to check whether the current query has been aborted
318+
const abortControllerRef = abortController;
319+
316320
// reset old state data
317321
state.data = [];
318322
state.metadata = {
@@ -369,6 +373,11 @@ export const usePanelDataLoader = (
369373
traceparent,
370374
});
371375

376+
// if aborted, return
377+
if (abortControllerRef?.signal?.aborted) {
378+
return;
379+
}
380+
372381
// partition array from api response
373382
const partitionArr = res?.data?.partitions ?? [];
374383

@@ -387,10 +396,6 @@ export const usePanelDataLoader = (
387396

388397
const currentQueryIndex = state.data.length - 1;
389398

390-
// copy of current abortController
391-
// which is used to check whether the current query has been aborted
392-
const abortControllerRef = abortController;
393-
394399
// Update the metadata for the current query
395400
Object.assign(state.metadata.queries[currentQueryIndex], metadata);
396401

@@ -399,6 +404,8 @@ export const usePanelDataLoader = (
399404

400405
// loop on all partitions and call search api for each partition
401406
for (let i = partitionArr.length - 1; i >= 0; i--) {
407+
state.loading = true;
408+
402409
const partition = partitionArr[i];
403410

404411
if (abortControllerRef?.signal?.aborted) {
@@ -436,9 +443,9 @@ export const usePanelDataLoader = (
436443
searchRes.data.is_partial != true
437444
) {
438445
// abort on unmount
439-
if (abortController) {
446+
if (abortControllerRef) {
440447
// this will stop partition api call
441-
abortController.abort();
448+
abortControllerRef?.abort();
442449
}
443450

444451
// throw error
@@ -447,6 +454,11 @@ export const usePanelDataLoader = (
447454
);
448455
}
449456

457+
// if the query is aborted or the response is partial, break the loop
458+
if (abortControllerRef?.signal?.aborted) {
459+
break;
460+
}
461+
450462
state.data[currentQueryIndex] = [
451463
...searchRes.data.hits,
452464
...(state.data[currentQueryIndex] ?? []),
@@ -455,11 +467,6 @@ export const usePanelDataLoader = (
455467
// update result metadata
456468
state.resultMetaData[currentQueryIndex] = searchRes.data ?? {};
457469

458-
// if the query is aborted or the response is partial, break the loop
459-
if (abortControllerRef?.signal?.aborted) {
460-
break;
461-
}
462-
463470
if (searchRes.data.is_partial == true) {
464471
// set the new start time as the start time of query
465472
state.resultMetaData[currentQueryIndex].new_end_time =
@@ -515,8 +522,8 @@ export const usePanelDataLoader = (
515522
state.loading = false;
516523

517524
// abort on done
518-
if (abortController) {
519-
abortController.abort();
525+
if (abortControllerRef) {
526+
abortControllerRef?.abort();
520527
}
521528
}
522529
}

web/src/utils/dashboard/convertSQLData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export const convertSQLData = async (
236236
}
237237

238238
// Extract and process metaDataStartTime
239-
const metaDataStartTime = metadata.queries[0].startTime.toString();
239+
const metaDataStartTime = metadata?.queries[0]?.startTime?.toString() ?? 0;
240240
const startTime = new Date(parseInt(metaDataStartTime) / 1000);
241241

242242
// Calculate the binnedDate
@@ -264,7 +264,7 @@ export const convertSQLData = async (
264264
}
265265

266266
// Extract and process metaDataEndTime
267-
const metaDataEndTime = metadata.queries[0].endTime.toString();
267+
const metaDataEndTime = metadata?.queries[0]?.endTime?.toString() ?? 0;
268268
const endTime = new Date(parseInt(metaDataEndTime) / 1000);
269269

270270
const xAxisKeysWithoutTimeStamp = getXAxisKeys().filter(

0 commit comments

Comments
 (0)