TimeSeries: fix & optimize time string parsing (#64640)

This commit is contained in:
Leon Sorokin
2023-03-13 09:59:40 -05:00
committed by GitHub
parent 8bb10f87e9
commit 855de98133
4 changed files with 53 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ import {
SortedVector,
TimeRange,
} from '@grafana/data';
import { convertFieldType } from '@grafana/data/src/transformations/transformers/convertFieldType';
import { GraphFieldConfig, LineInterpolation } from '@grafana/schema';
import { applyNullInsertThreshold } from '@grafana/ui/src/components/GraphNG/nullInsertThreshold';
import { nullToValue } from '@grafana/ui/src/components/GraphNG/nullToValue';
@@ -29,6 +30,17 @@ export function prepareGraphableFields(
return null;
}
// some datasources simply tag the field as time, but don't convert to milli epochs
// so we're stuck with doing the parsing here to avoid Moment slowness everywhere later
// this mutates (once)
for (let frame of series) {
for (let field of frame.fields) {
if (field.type === FieldType.time && typeof field.values.get(0) !== 'number') {
field.values = convertFieldType(field, { destinationType: FieldType.time }).values;
}
}
}
if (series.every((df) => df.meta?.type === DataFrameType.TimeSeriesLong)) {
series = prepareTimeSeriesLong(series);
}