mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 07:35:45 -06:00
Influxdb: Fix toMetricFindValue
function (#90514)
Improved toMetricFindValue to be quicker
This commit is contained in:
parent
88ed77e7e8
commit
41ae376aa4
@ -30,7 +30,6 @@ import {
|
||||
BackendDataSourceResponse,
|
||||
DataSourceWithBackend,
|
||||
FetchResponse,
|
||||
frameToMetricFindValue,
|
||||
getBackendSrv,
|
||||
getTemplateSrv,
|
||||
TemplateSrv,
|
||||
@ -414,13 +413,23 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
}
|
||||
|
||||
toMetricFindValue(rsp: DataQueryResponse): MetricFindValue[] {
|
||||
const data = rsp.data ?? [];
|
||||
const valueMap = new Map<string, MetricFindValue>();
|
||||
// Create MetricFindValue object for all frames
|
||||
const values = data.map((d) => frameToMetricFindValue(d)).flat();
|
||||
// Filter out duplicate elements
|
||||
return values.filter((elm, idx, self) => idx === self.findIndex((t) => t.text === elm.text));
|
||||
rsp?.data?.forEach((frame: DataFrame) => {
|
||||
if (frame && frame.length > 0) {
|
||||
let field = frame.fields.find((f) => f.type === FieldType.string);
|
||||
if (!field) {
|
||||
field = frame.fields.find((f) => f.type !== FieldType.time);
|
||||
}
|
||||
if (field) {
|
||||
field.values.forEach((v) => {
|
||||
valueMap.set(v.toString(), { text: v.toString() });
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return Array.from(valueMap.values());
|
||||
}
|
||||
|
||||
// By implementing getTagKeys and getTagValues we add ad-hoc filters functionality
|
||||
// Used in public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx::fetchFilterKeys
|
||||
getTagKeys(options?: DataSourceGetTagKeysOptions<InfluxQuery>) {
|
||||
|
Loading…
Reference in New Issue
Block a user