mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 16:53:17 +08:00
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:
@ -1,4 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import { clone, filter, find, findIndex, indexOf, map } from 'lodash';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { PostgresMetaQuery } from './meta_query';
|
||||
import { QueryCtrl } from 'app/plugins/sdk';
|
||||
@ -112,23 +112,23 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
updateProjection() {
|
||||
this.selectParts = _.map(this.target.select, (parts: any) => {
|
||||
return _.map(parts, sqlPart.create).filter((n) => n);
|
||||
this.selectParts = map(this.target.select, (parts: any) => {
|
||||
return map(parts, sqlPart.create).filter((n) => n);
|
||||
});
|
||||
this.whereParts = _.map(this.target.where, sqlPart.create).filter((n) => n);
|
||||
this.groupParts = _.map(this.target.group, sqlPart.create).filter((n) => n);
|
||||
this.whereParts = map(this.target.where, sqlPart.create).filter((n) => n);
|
||||
this.groupParts = map(this.target.group, sqlPart.create).filter((n) => n);
|
||||
}
|
||||
|
||||
updatePersistedParts() {
|
||||
this.target.select = _.map(this.selectParts, (selectParts) => {
|
||||
return _.map(selectParts, (part: any) => {
|
||||
this.target.select = map(this.selectParts, (selectParts) => {
|
||||
return map(selectParts, (part: any) => {
|
||||
return { type: part.def.type, datatype: part.datatype, params: part.params };
|
||||
});
|
||||
});
|
||||
this.target.where = _.map(this.whereParts, (part: any) => {
|
||||
this.target.where = map(this.whereParts, (part: any) => {
|
||||
return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
|
||||
});
|
||||
this.target.group = _.map(this.groupParts, (part: any) => {
|
||||
this.target.group = map(this.groupParts, (part: any) => {
|
||||
return { type: part.def.type, datatype: part.datatype, params: part.params };
|
||||
});
|
||||
}
|
||||
@ -233,7 +233,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
const task1 = this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery('time')).then((result: any) => {
|
||||
// check if time column is still valid
|
||||
if (result.length > 0 && !_.find(result, (r: any) => r.text === this.target.timeColumn)) {
|
||||
if (result.length > 0 && !find(result, (r: any) => r.text === this.target.timeColumn)) {
|
||||
const segment = this.uiSegmentSrv.newSegment(result[0].text);
|
||||
this.timeColumnSegment.html = segment.html;
|
||||
this.timeColumnSegment.value = segment.value;
|
||||
@ -318,7 +318,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
transformToSegments(config: { addNone?: any; addTemplateVars?: any; templateQuoter?: any }) {
|
||||
return (results: any) => {
|
||||
const segments = _.map(results, (segment) => {
|
||||
const segments = map(results, (segment) => {
|
||||
return this.uiSegmentSrv.newSegment({
|
||||
value: segment.text,
|
||||
expandable: segment.expandable,
|
||||
@ -352,11 +352,11 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
findAggregateIndex(selectParts: any) {
|
||||
return _.findIndex(selectParts, (p: any) => p.def.type === 'aggregate' || p.def.type === 'percentile');
|
||||
return findIndex(selectParts, (p: any) => p.def.type === 'aggregate' || p.def.type === 'percentile');
|
||||
}
|
||||
|
||||
findWindowIndex(selectParts: any) {
|
||||
return _.findIndex(selectParts, (p: any) => p.def.type === 'window' || p.def.type === 'moving_window');
|
||||
return findIndex(selectParts, (p: any) => p.def.type === 'window' || p.def.type === 'moving_window');
|
||||
}
|
||||
|
||||
addSelectPart(selectParts: any[], item: { value: any }, subItem: { type: any; value: any }) {
|
||||
@ -372,8 +372,8 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
switch (partType) {
|
||||
case 'column':
|
||||
const parts = _.map(selectParts, (part: any) => {
|
||||
return sqlPart.create({ type: part.def.type, params: _.clone(part.params) });
|
||||
const parts = map(selectParts, (part: any) => {
|
||||
return sqlPart.create({ type: part.def.type, params: clone(part.params) });
|
||||
});
|
||||
this.selectParts.push(parts);
|
||||
break;
|
||||
@ -390,7 +390,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
} else {
|
||||
selectParts.splice(1, 0, partModel);
|
||||
}
|
||||
if (!_.find(selectParts, (p: any) => p.def.type === 'alias')) {
|
||||
if (!find(selectParts, (p: any) => p.def.type === 'alias')) {
|
||||
addAlias = true;
|
||||
}
|
||||
break;
|
||||
@ -408,7 +408,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
selectParts.splice(1, 0, partModel);
|
||||
}
|
||||
}
|
||||
if (!_.find(selectParts, (p: any) => p.def.type === 'alias')) {
|
||||
if (!find(selectParts, (p: any) => p.def.type === 'alias')) {
|
||||
addAlias = true;
|
||||
}
|
||||
break;
|
||||
@ -435,11 +435,11 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
if (part.def.type === 'column') {
|
||||
// remove all parts of column unless its last column
|
||||
if (this.selectParts.length > 1) {
|
||||
const modelsIndex = _.indexOf(this.selectParts, selectParts);
|
||||
const modelsIndex = indexOf(this.selectParts, selectParts);
|
||||
this.selectParts.splice(modelsIndex, 1);
|
||||
}
|
||||
} else {
|
||||
const partIndex = _.indexOf(selectParts, part);
|
||||
const partIndex = indexOf(selectParts, part);
|
||||
selectParts.splice(partIndex, 1);
|
||||
}
|
||||
|
||||
@ -534,8 +534,8 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
removeGroup(part: { def: { type: string } }, index: number) {
|
||||
if (part.def.type === 'time') {
|
||||
// remove aggregations
|
||||
this.selectParts = _.map(this.selectParts, (s: any) => {
|
||||
return _.filter(s, (part: any) => {
|
||||
this.selectParts = map(this.selectParts, (s: any) => {
|
||||
return filter(s, (part: any) => {
|
||||
if (part.def.type === 'aggregate' || part.def.type === 'percentile') {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user