Skip to content

Commit

Permalink
Optimize performance for document table
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes committed Jun 9, 2021
1 parent 12986fb commit 6994400
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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;
}

0 comments on commit 6994400

Please sign in to comment.