From 683f31f2c6e4f4cd997ea46b16418c230b758450 Mon Sep 17 00:00:00 2001 From: Nathaniel Saxe Date: Mon, 27 Jun 2022 11:26:46 +0000 Subject: [PATCH] Variables: improve performance of transformMetricFindResponse (#49360) * improve performance of transformMetricFindResponse * use lodash uniqBy for postgres * use lodash uniqBy for mysql * use lodash uniqBy for mssql * hopefully conform to import linting rules * Added .betterer.results Co-authored-by: Dominik Prokop Co-authored-by: Victor Marin --- .betterer.results | 24 +++++++++---------- .../datasource/mssql/response_parser.ts | 7 +++--- .../datasource/mysql/response_parser.ts | 7 +++--- .../datasource/postgres/response_parser.ts | 7 +++--- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.betterer.results b/.betterer.results index 2b22be0f1e0..959b2106020 100644 --- a/.betterer.results +++ b/.betterer.results @@ -9466,10 +9466,10 @@ exports[`better eslint`] = { [51, 27, 3, "Unexpected any. Specify a different type.", "193409811"], [56, 19, 3, "Unexpected any. Specify a different type.", "193409811"] ], - "public/app/plugins/datasource/mssql/response_parser.ts:4040977456": [ - [5, 19, 44, "Do not use any type assertions.", "1721934533"], - [37, 45, 3, "Unexpected any. Specify a different type.", "193409811"], - [38, 19, 55, "Do not use any type assertions.", "52331741"] + "public/app/plugins/datasource/mssql/response_parser.ts:3188817026": [ + [7, 19, 44, "Do not use any type assertions.", "1721934533"], + [36, 45, 3, "Unexpected any. Specify a different type.", "193409811"], + [37, 19, 55, "Do not use any type assertions.", "52331741"] ], "public/app/plugins/datasource/mssql/specs/datasource.test.ts:1031027185": [ [11, 6, 59, "Do not use any type assertions.", "3685154675"], @@ -9590,10 +9590,10 @@ exports[`better eslint`] = { [642, 24, 3, "Unexpected any. Specify a different type.", "193409811"], [642, 30, 3, "Unexpected any. Specify a different type.", "193409811"] ], - "public/app/plugins/datasource/mysql/response_parser.ts:2781493345": [ - [5, 19, 44, "Do not use any type assertions.", "1721934533"], - [37, 45, 3, "Unexpected any. Specify a different type.", "193409811"], - [38, 19, 55, "Do not use any type assertions.", "52331741"] + "public/app/plugins/datasource/mysql/response_parser.ts:2094461587": [ + [7, 19, 44, "Do not use any type assertions.", "1721934533"], + [36, 45, 3, "Unexpected any. Specify a different type.", "193409811"], + [37, 19, 55, "Do not use any type assertions.", "52331741"] ], "public/app/plugins/datasource/mysql/specs/datasource.test.ts:3991124757": [ [19, 38, 3, "Unexpected any. Specify a different type.", "193409811"], @@ -9850,10 +9850,10 @@ exports[`better eslint`] = { [688, 24, 3, "Unexpected any. Specify a different type.", "193409811"], [688, 30, 3, "Unexpected any. Specify a different type.", "193409811"] ], - "public/app/plugins/datasource/postgres/response_parser.ts:2077296207": [ - [5, 19, 44, "Do not use any type assertions.", "1721934533"], - [37, 45, 3, "Unexpected any. Specify a different type.", "193409811"], - [38, 19, 55, "Do not use any type assertions.", "52331741"] + "public/app/plugins/datasource/postgres/response_parser.ts:2167297341": [ + [7, 19, 44, "Do not use any type assertions.", "1721934533"], + [36, 45, 3, "Unexpected any. Specify a different type.", "193409811"], + [37, 19, 55, "Do not use any type assertions.", "52331741"] ], "public/app/plugins/datasource/postgres/specs/datasource.test.ts:2366687477": [ [19, 6, 59, "Do not use any type assertions.", "3685154675"], diff --git a/public/app/plugins/datasource/mssql/response_parser.ts b/public/app/plugins/datasource/mssql/response_parser.ts index 05a853170a6..52e2af016e3 100644 --- a/public/app/plugins/datasource/mssql/response_parser.ts +++ b/public/app/plugins/datasource/mssql/response_parser.ts @@ -1,3 +1,5 @@ +import { uniqBy } from 'lodash'; + import { AnnotationEvent, DataFrame, MetricFindValue } from '@grafana/data'; import { BackendDataSourceResponse, toDataQueryResponse, FetchResponse } from '@grafana/runtime'; @@ -29,10 +31,7 @@ export default class ResponseParser { ); } - return Array.from(new Set(values.map((v) => v.text))).map((text) => ({ - text, - value: values.find((v) => v.text === text)?.value, - })); + return uniqBy(values, 'text'); } async transformAnnotationResponse(options: any, data: BackendDataSourceResponse): Promise { diff --git a/public/app/plugins/datasource/mysql/response_parser.ts b/public/app/plugins/datasource/mysql/response_parser.ts index c4367a9c402..ff16bd60551 100644 --- a/public/app/plugins/datasource/mysql/response_parser.ts +++ b/public/app/plugins/datasource/mysql/response_parser.ts @@ -1,3 +1,5 @@ +import { uniqBy } from 'lodash'; + import { AnnotationEvent, DataFrame, MetricFindValue } from '@grafana/data'; import { BackendDataSourceResponse, FetchResponse, toDataQueryResponse } from '@grafana/runtime'; @@ -29,10 +31,7 @@ export default class ResponseParser { ); } - return Array.from(new Set(values.map((v) => v.text))).map((text) => ({ - text, - value: values.find((v) => v.text === text)?.value, - })); + return uniqBy(values, 'text'); } async transformAnnotationResponse(options: any, data: BackendDataSourceResponse): Promise { diff --git a/public/app/plugins/datasource/postgres/response_parser.ts b/public/app/plugins/datasource/postgres/response_parser.ts index 83ecc223984..c5a6e8af852 100644 --- a/public/app/plugins/datasource/postgres/response_parser.ts +++ b/public/app/plugins/datasource/postgres/response_parser.ts @@ -1,3 +1,5 @@ +import { uniqBy } from 'lodash'; + import { AnnotationEvent, DataFrame, MetricFindValue } from '@grafana/data'; import { BackendDataSourceResponse, FetchResponse, toDataQueryResponse } from '@grafana/runtime'; @@ -29,10 +31,7 @@ export default class ResponseParser { ); } - return Array.from(new Set(values.map((v) => v.text))).map((text) => ({ - text, - value: values.find((v) => v.text === text)?.value, - })); + return uniqBy(values, 'text'); } async transformAnnotationResponse(options: any, data: BackendDataSourceResponse): Promise {