mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
# Backport This will backport the following commits from `main` to `8.5`: - [[Discover] Improve performance of getFieldsToShow (#144672)](https://github.com/elastic/kibana/pull/144672) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Matthias Wilhelm","email":"matthias.wilhelm@elastic.co"},"sourceCommit":{"committedDate":"2022-11-16T17:53:18Z","message":"[Discover] Improve performance of getFieldsToShow (#144672)\n\n## Summary\r\n\r\nSignificantly improves the performance of `getFieldsToShow` for very large data views (>=100k). This is done by reducing the number ofiterations necessary to detect multi fields shat should not be displayed.","sha":"1ffb93d687e899ec93b4e1735458e9e2863d6b39","branchLabelMapping":{"^v8.6.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","v8.6.0","v7.17.8","v8.7.0","v8.5.2"],"number":144672,"url":"https://github.com/elastic/kibana/pull/144672","mergeCommit":{"message":"[Discover] Improve performance of getFieldsToShow (#144672)\n\n## Summary\r\n\r\nSignificantly improves the performance of `getFieldsToShow` for very large data views (>=100k). This is done by reducing the number ofiterations necessary to detect multi fields shat should not be displayed.","sha":"1ffb93d687e899ec93b4e1735458e9e2863d6b39"}},"sourceBranch":"main","suggestedTargetBranches":["7.17","8.7","8.5"],"targetPullRequestStates":[{"branch":"main","label":"v8.6.0","labelRegex":"^v8.6.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/144672","number":144672,"mergeCommit":{"message":"[Discover] Improve performance of getFieldsToShow (#144672)\n\n## Summary\r\n\r\nSignificantly improves the performance of `getFieldsToShow` for very large data views (>=100k). This is done by reducing the number ofiterations necessary to detect multi fields shat should not be displayed.","sha":"1ffb93d687e899ec93b4e1735458e9e2863d6b39"}},{"branch":"7.17","label":"v7.17.8","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.5","label":"v8.5.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
This commit is contained in:
parent
f74a1f082e
commit
d08bc2fc2c
1 changed files with 24 additions and 10 deletions
|
@ -8,24 +8,38 @@
|
|||
import { getFieldSubtypeMulti } from '@kbn/data-views-plugin/public';
|
||||
import type { DataView } from '@kbn/data-views-plugin/public';
|
||||
|
||||
/**
|
||||
* Returns am array of fields to display in the Documents column of the data table
|
||||
* If showMultiFields is set to false, it filters out multifields that have a parent, to prevent entries for multifields
|
||||
* like this: field, field.keyword, field.whatever
|
||||
* @param fields
|
||||
* @param dataView
|
||||
* @param showMultiFields
|
||||
*/
|
||||
export const getFieldsToShow = (fields: string[], dataView: DataView, showMultiFields: boolean) => {
|
||||
const childParentFieldsMap = {} as Record<string, string>;
|
||||
const mapping = (name: string) => dataView.fields.getByName(name);
|
||||
if (showMultiFields) {
|
||||
return fields;
|
||||
}
|
||||
const fieldSet = new Set();
|
||||
const childParentFieldsMap = new Map();
|
||||
const parentFieldSet = new Set();
|
||||
fields.forEach((key) => {
|
||||
const mapped = mapping(key);
|
||||
const mapped = dataView.fields.getByName(key);
|
||||
const subTypeMulti = mapped && getFieldSubtypeMulti(mapped.spec);
|
||||
const isMultiField = Boolean(subTypeMulti?.multi);
|
||||
if (mapped && subTypeMulti?.multi?.parent) {
|
||||
childParentFieldsMap[mapped.name] = subTypeMulti.multi.parent;
|
||||
childParentFieldsMap.set(key, subTypeMulti.multi.parent);
|
||||
}
|
||||
if (mapped && isMultiField) {
|
||||
parentFieldSet.add(key);
|
||||
}
|
||||
fieldSet.add(key);
|
||||
});
|
||||
return fields.filter((key: string) => {
|
||||
const fieldMapping = mapping(key);
|
||||
const subTypeMulti = fieldMapping && getFieldSubtypeMulti(fieldMapping.spec);
|
||||
const isMultiField = !!subTypeMulti?.multi;
|
||||
if (!isMultiField) {
|
||||
if (!parentFieldSet.has(key)) {
|
||||
return true;
|
||||
}
|
||||
const parent = childParentFieldsMap[key];
|
||||
return showMultiFields || (parent && !fields.includes(parent));
|
||||
const parent = childParentFieldsMap.get(key);
|
||||
return parent && !fieldSet.has(parent);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue