Optimize performance for document table (#101715) (#101774)

Co-authored-by: Tim Roes <tim.roes@elastic.co>
This commit is contained in:
Kibana Machine 2021-06-09 12:36:21 -04:00 committed by GitHub
parent 009a6d02be
commit e4a251d043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -43,4 +43,9 @@ describe('getDisplayedColumns', () => {
]
`);
});
test('returns the same instance of ["_source"] over multiple calls', async () => {
const result = getDisplayedColumns([], indexPatternWithTimefieldMock);
const result2 = getDisplayedColumns([], indexPatternWithTimefieldMock);
expect(result).toBe(result2);
});
});

View file

@ -8,6 +8,11 @@
import { IndexPattern } from '../../../../data/common';
// We store this outside the function as a constant, so we're not creating a new array every time
// the function is returning this. A changing array might cause the data grid to think it got
// new columns, and thus performing worse than using the same array over multiple renders.
const SOURCE_ONLY = ['_source'];
/**
* Function to provide fallback when
* 1) no columns are given
@ -19,5 +24,5 @@ export function getDisplayedColumns(stateColumns: string[] = [], indexPattern: I
// check if all columns where removed except the configured timeField (this can't be removed)
!(stateColumns.length === 1 && stateColumns[0] === indexPattern.timeFieldName)
? stateColumns
: ['_source'];
: SOURCE_ONLY;
}