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 { once, chain, difference } from 'lodash';
import LRU from 'lru-cache';
import { Value } from 'slate';
@@ -204,7 +204,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
const suggestions: CompletionItemGroup[] = [];
if (history && history.length) {
const historyItems = _.chain(history)
const historyItems = chain(history)
.map((h) => h.query.expr)
.filter()
.uniq()
@@ -389,7 +389,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
const labelKeys = labelValues ? Object.keys(labelValues) : containsMetric ? null : DEFAULT_KEYS;
if (labelKeys) {
const possibleKeys = _.difference(labelKeys, existingKeys);
const possibleKeys = difference(labelKeys, existingKeys);
if (possibleKeys.length) {
context = 'context-labels';
const newItems = possibleKeys.map((key) => ({ label: key }));
@@ -472,7 +472,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
* because we can cache more aggressively here and also we do not want to invalidate this cache the same way as in
* fetchSeriesLabels.
*/
fetchDefaultLabels = _.once(async () => {
fetchDefaultLabels = once(async () => {
const values = await Promise.all(DEFAULT_KEYS.map((key) => this.fetchLabelValues(key)));
return values.reduce((acc, value) => ({ ...acc, ...value }), {});
});