Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Optimize performance for document table (#101715) #101774

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
7 changes: 6 additions & 1 deletion src/plugins/discover/public/application/helpers/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}