Performance: Standardize lodash imports to use destructured members (#33040)

* Performance: Standardize lodash imports to use destructured members
Changes lodash imports of the form `import x from 'lodash/x'` to
`import { x } from 'lodash'` to reduce bundle size.

* Remove unnecessary _ import from Graph component

* Enforce lodash import style

* Fix remaining lodash imports
This commit is contained in:
kay delaney
2021-04-21 08:38:00 +01:00
committed by GitHub
parent 2bb7eb18d1
commit bad048b7ba
299 changed files with 1135 additions and 1137 deletions

View File

@ -1,4 +1,4 @@
import _ from 'lodash';
import { find, map } from 'lodash';
import { TemplateSrv } from '@grafana/runtime';
import { ScopedVars } from '@grafana/data';
@ -58,7 +58,7 @@ export default class MysqlQuery {
}
hasTimeGroup() {
return _.find(this.target.group, (g: any) => g.type === 'time');
return find(this.target.group, (g: any) => g.type === 'time');
}
hasMetricColumn() {
@ -75,7 +75,7 @@ export default class MysqlQuery {
return this.quoteLiteral(value);
}
const escapedValues = _.map(value, this.quoteLiteral);
const escapedValues = map(value, this.quoteLiteral);
return escapedValues.join(',');
}
@ -151,17 +151,17 @@ export default class MysqlQuery {
buildValueColumn(column: any) {
let query = '';
const columnName: any = _.find(column, (g: any) => g.type === 'column');
const columnName: any = find(column, (g: any) => g.type === 'column');
query = columnName.params[0];
const aggregate: any = _.find(column, (g: any) => g.type === 'aggregate');
const aggregate: any = find(column, (g: any) => g.type === 'aggregate');
if (aggregate) {
const func = aggregate.params[0];
query = func + '(' + query + ')';
}
const alias: any = _.find(column, (g: any) => g.type === 'alias');
const alias: any = find(column, (g: any) => g.type === 'alias');
if (alias) {
query += ' AS ' + this.quoteIdentifier(alias.params[0]);
}
@ -171,7 +171,7 @@ export default class MysqlQuery {
buildWhereClause() {
let query = '';
const conditions = _.map(this.target.where, (tag, index) => {
const conditions = map(this.target.where, (tag, index) => {
switch (tag.type) {
case 'macro':
return tag.name + '(' + this.target.timeColumn + ')';