mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 07:47:16 +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 { find } from 'lodash';
|
||||
import {
|
||||
createChangeHandler,
|
||||
createResetHandler,
|
||||
@ -55,7 +55,7 @@ export class PostgresConfigCtrl {
|
||||
if (version < 1000) {
|
||||
name = String(major) + '.' + String(minor);
|
||||
}
|
||||
if (!_.find(this.postgresVersions, (p: any) => p.value === version)) {
|
||||
if (!find(this.postgresVersions, (p: any) => p.value === version)) {
|
||||
this.postgresVersions.push({ name: name, value: version });
|
||||
}
|
||||
this.current.jsonData.postgresVersion = version;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import { map as _map, filter } from 'lodash';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
@ -46,7 +46,7 @@ export class PostgresDatasource {
|
||||
return value;
|
||||
}
|
||||
|
||||
const quotedValues = _.map(value, (v) => {
|
||||
const quotedValues = _map(value, (v) => {
|
||||
return this.queryModel.quoteLiteral(v);
|
||||
});
|
||||
return quotedValues.join(',');
|
||||
@ -72,7 +72,7 @@ export class PostgresDatasource {
|
||||
}
|
||||
|
||||
query(options: any): Observable<DataQueryResponse> {
|
||||
const queries = _.filter(options.targets, (target) => {
|
||||
const queries = filter(options.targets, (target) => {
|
||||
return target.hide !== true;
|
||||
}).map((target) => {
|
||||
const queryModel = new PostgresQuery(target, this.templateSrv, options.scopedVars);
|
||||
|
@ -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 PostgresQuery {
|
||||
}
|
||||
|
||||
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 PostgresQuery {
|
||||
return this.quoteLiteral(value);
|
||||
}
|
||||
|
||||
const escapedValues = _.map(value, this.quoteLiteral);
|
||||
const escapedValues = map(value, this.quoteLiteral);
|
||||
return escapedValues.join(',');
|
||||
}
|
||||
|
||||
@ -151,11 +151,11 @@ export default class PostgresQuery {
|
||||
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' || g.type === 'percentile');
|
||||
const windows: any = _.find(column, (g: any) => g.type === 'window' || g.type === 'moving_window');
|
||||
const aggregate: any = find(column, (g: any) => g.type === 'aggregate' || g.type === 'percentile');
|
||||
const windows: any = find(column, (g: any) => g.type === 'window' || g.type === 'moving_window');
|
||||
|
||||
if (aggregate) {
|
||||
const func = aggregate.params[0];
|
||||
@ -220,7 +220,7 @@ export default class PostgresQuery {
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
@ -230,7 +230,7 @@ export default class PostgresQuery {
|
||||
|
||||
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 + ')';
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import { map } from 'lodash';
|
||||
|
||||
export default class ResponseParser {
|
||||
processQueryResult(res: any) {
|
||||
@ -78,7 +78,7 @@ export default class ResponseParser {
|
||||
|
||||
const unique = Array.from(new Set(res));
|
||||
|
||||
return _.map(unique, (value) => {
|
||||
return map(unique, (value) => {
|
||||
return { text: value };
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user