From a5b1092968e17efef5d5acbc55a8a2fa27689a4f Mon Sep 17 00:00:00 2001 From: Fine Date: Tue, 30 Jul 2024 18:58:31 +0800 Subject: [PATCH] feat: split query --- src/hooks/useExpressionsProcessor.ts | 47 +++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/hooks/useExpressionsProcessor.ts b/src/hooks/useExpressionsProcessor.ts index c77745f1..f1fbed73 100644 --- a/src/hooks/useExpressionsProcessor.ts +++ b/src/hooks/useExpressionsProcessor.ts @@ -156,7 +156,7 @@ export async function useExpressionsQueryProcessor(config: Indexable) { } export async function useExpressionsQueryPodsMetrics( - pods: Array<(Instance | Endpoint | Service) & Indexable>, + allPods: Array<(Instance | Endpoint | Service) & Indexable>, config: { expressions: string[]; subExpressions: string[]; @@ -164,7 +164,7 @@ export async function useExpressionsQueryPodsMetrics( }, scope: string, ) { - function expressionsGraphqlPods() { + function expressionsGraphqlPods(pods: Array<(Instance | Endpoint | Service) & Indexable>) { const metrics: string[] = []; const subMetrics: string[] = []; config.expressions = config.expressions || []; @@ -222,7 +222,10 @@ export async function useExpressionsQueryPodsMetrics( return { queryStr, conditions }; } - function expressionsPodsSource(resp: { errors: string; data: Indexable }): Indexable { + function expressionsPodsSource( + resp: { errors: string; data: Indexable }, + pods: Array<(Instance | Endpoint | Service) & Indexable>, + ): Indexable { if (resp.errors) { ElMessage.error(resp.errors); return {}; @@ -304,17 +307,39 @@ export async function useExpressionsQueryPodsMetrics( return { data, names, subNames, metricConfigArr, metricTypesArr, expressionsTips, subExpressionsTips }; } - const dashboardStore = useDashboardStore(); - const params = await expressionsGraphqlPods(); - const json = await dashboardStore.fetchMetricValue(params); + async function fetchPodsExpressionValues(pods: Array<(Instance | Endpoint | Service) & Indexable>) { + const dashboardStore = useDashboardStore(); + const params = await expressionsGraphqlPods(pods); - if (json.errors) { - ElMessage.error(json.errors); - return {}; + const json = await dashboardStore.fetchMetricValue(params); + + if (json.errors) { + ElMessage.error(json.errors); + return {}; + } + const expressionParams = expressionsPodsSource(json, pods); + + return expressionParams; } - const expressionParams = expressionsPodsSource(json); - return expressionParams; + const result = []; + for (let i = 0; i < allPods.length; i += 20) { + result.push(allPods.slice(i, i + 20)); + } + const promiseArr = result.map((d: Array<(Instance | Endpoint | Service) & Indexable>) => + fetchPodsExpressionValues(d), + ); + const responseList = await Promise.all(promiseArr); + let resp: Indexable = { data: [], expressionsTips: [], subExpressionsTips: [] }; + for (const item of responseList) { + resp = { + ...item, + data: [...resp.data, ...item.data], + expressionsTips: [...resp.expressionsTips, ...item.expressionsTips], + subExpressionsTips: [...resp.subExpressionsTips, ...item.subExpressionsTips], + }; + } + return resp; } export function useQueryTopologyExpressionsProcessor(metrics: string[], instances: (Call | Node)[]) {