-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Improve performance for unmapped fields (#159113)
Enhanced Discover performance for scenarios with numerous unmapped fields. While investigating an edge case involving 4k unmapped fields, an issue was identified in our nested field detection code, resulting in significant processing time. This commit optimizes the code by addressing redundant RegEx execution, resulting in a performance boost for the specific scenario.
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/kbn-discover-utils/src/utils/nested_fields.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { DataView } from '@kbn/data-views-plugin/common'; | ||
import { isNestedFieldParent } from './nested_fields'; | ||
describe('isNestedFieldParent', () => { | ||
it('correctly identifies nested parent fields', () => { | ||
const nestedField = { | ||
name: 'nested.field', | ||
type: 'keyword', | ||
subType: { | ||
nested: { | ||
path: 'nested.field.path', | ||
}, | ||
}, | ||
}; | ||
const unnestedField = { | ||
name: 'unnested.field', | ||
type: 'keyword', | ||
}; | ||
const list = [nestedField, unnestedField]; | ||
|
||
const dataView = { | ||
fields: { | ||
getByName: jest.fn((fieldName) => list.find((field) => field.name === fieldName)), | ||
getAll: jest.fn(() => list), | ||
}, | ||
} as unknown as DataView; | ||
|
||
expect(isNestedFieldParent('nested', dataView)).toBe(true); | ||
expect(isNestedFieldParent('nested.field', dataView)).toBe(false); | ||
expect(isNestedFieldParent('unnested.field', dataView)).toBe(false); | ||
expect(isNestedFieldParent('whateverField', dataView)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters