Skip to content

Commit 3e69858

Browse files
committed
[security solution] only import beat_schema when needed
1 parent da134f3 commit 3e69858

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

x-pack/plugins/security_solution/server/search_strategy/index_fields/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ describe('Index Fields', () => {
747747
});
748748

749749
describe('createFieldItem', () => {
750-
test('Basic functionality', () => {
751-
const item = createFieldItem(
750+
test('Basic functionality', async () => {
751+
const item = await createFieldItem(
752752
['auditbeat'],
753753
{
754754
name: '_id',

x-pack/plugins/security_solution/server/search_strategy/index_fields/index.ts

+16-24
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
IndexFieldsStrategyRequest,
1515
} from '../../../common/search_strategy/index_fields';
1616

17-
import { fieldsBeat } from '../../utils/beat_schema/fields';
18-
1917
export const securitySolutionIndexFieldsProvider = (): ISearchStrategy<
2018
IndexFieldsStrategyRequest,
2119
IndexFieldsStrategyResponse
@@ -115,11 +113,13 @@ const missingFields: FieldDescriptor[] = [
115113
* @param index The index its self
116114
* @param indexesAliasIdx The index within the alias
117115
*/
118-
export const createFieldItem = (
116+
export const createFieldItem = async (
119117
indexesAlias: string[],
120118
index: FieldDescriptor,
121119
indexesAliasIdx: number
122-
): IndexField => {
120+
): Promise<IndexField> => {
121+
const { fieldsBeat } = await import('../../utils/beat_schema/fields');
122+
123123
const alias = indexesAlias[indexesAliasIdx];
124124
const splitIndexName = index.name.split('.');
125125
const indexName =
@@ -154,26 +154,18 @@ export const formatFirstFields = async (
154154
responsesIndexFields: FieldDescriptor[][],
155155
indexesAlias: string[]
156156
): Promise<IndexField[]> => {
157-
return new Promise((resolve) => {
158-
setTimeout(() => {
159-
resolve(
160-
responsesIndexFields.reduce(
161-
(accumulator: IndexField[], indexFields: FieldDescriptor[], indexesAliasIdx: number) => {
162-
missingFields.forEach((index) => {
163-
const item = createFieldItem(indexesAlias, index, indexesAliasIdx);
164-
accumulator.push(item);
165-
});
166-
indexFields.forEach((index) => {
167-
const item = createFieldItem(indexesAlias, index, indexesAliasIdx);
168-
accumulator.push(item);
169-
});
170-
return accumulator;
171-
},
172-
[]
173-
)
174-
);
175-
});
176-
});
157+
const result: IndexField[] = [];
158+
159+
for (const [indexesAliasIdx, indexFields] of responsesIndexFields.entries()) {
160+
for (const index of missingFields) {
161+
result.push(await createFieldItem(indexesAlias, index, indexesAliasIdx));
162+
}
163+
for (const index of indexFields) {
164+
result.push(await createFieldItem(indexesAlias, index, indexesAliasIdx));
165+
}
166+
}
167+
168+
return result;
177169
};
178170

179171
/**

0 commit comments

Comments
 (0)