Skip to content

Commit cdb922f

Browse files
authored
Move indexPattern.popularizeField into discover (#77668)
Move indexPattern.popularizeField into discover
1 parent b1e60a6 commit cdb922f

19 files changed

+153
-155
lines changed

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Constructs a new instance of the `IndexPattern` class
99
<b>Signature:</b>
1010

1111
```typescript
12-
constructor({ spec, savedObjectsClient, fieldFormats, shortDotsEnable, metaFields, }: IndexPatternDeps);
12+
constructor({ spec, fieldFormats, shortDotsEnable, metaFields, }: IndexPatternDeps);
1313
```
1414

1515
## Parameters
1616

1717
| Parameter | Type | Description |
1818
| --- | --- | --- |
19-
| { spec, savedObjectsClient, fieldFormats, shortDotsEnable, metaFields, } | <code>IndexPatternDeps</code> | |
19+
| { spec, fieldFormats, shortDotsEnable, metaFields, } | <code>IndexPatternDeps</code> | |
2020

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export declare class IndexPattern implements IIndexPattern
1414
1515
| Constructor | Modifiers | Description |
1616
| --- | --- | --- |
17-
| [(constructor)({ spec, savedObjectsClient, fieldFormats, shortDotsEnable, metaFields, })](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
17+
| [(constructor)({ spec, fieldFormats, shortDotsEnable, metaFields, })](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
1818
1919
## Properties
2020
@@ -53,7 +53,6 @@ export declare class IndexPattern implements IIndexPattern
5353
| [getTimeField()](./kibana-plugin-plugins-data-public.indexpattern.gettimefield.md) | | |
5454
| [isTimeBased()](./kibana-plugin-plugins-data-public.indexpattern.istimebased.md) | | |
5555
| [isTimeNanosBased()](./kibana-plugin-plugins-data-public.indexpattern.istimenanosbased.md) | | |
56-
| [popularizeField(fieldName, unit)](./kibana-plugin-plugins-data-public.indexpattern.popularizefield.md) | | |
5756
| [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | Remove scripted field from field list |
5857
| [toSpec()](./kibana-plugin-plugins-data-public.indexpattern.tospec.md) | | |
5958

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.popularizefield.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ export declare class IndexPatternsService
4343
| [createAndSave(spec, override, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md) | | Create a new index pattern and save it right away |
4444
| [createSavedObject(indexPattern, override)](./kibana-plugin-plugins-data-public.indexpatternsservice.createsavedobject.md) | | Save a new index pattern |
4545
| [delete(indexPatternId)](./kibana-plugin-plugins-data-public.indexpatternsservice.delete.md) | | Deletes an index pattern from .kibana index |
46-
| [updateSavedObject(indexPattern, saveAttempts)](./kibana-plugin-plugins-data-public.indexpatternsservice.updatesavedobject.md) | | Save existing index pattern. Will attempt to merge differences if there are conflicts |
46+
| [updateSavedObject(indexPattern, saveAttempts, ignoreErrors)](./kibana-plugin-plugins-data-public.indexpatternsservice.updatesavedobject.md) | | Save existing index pattern. Will attempt to merge differences if there are conflicts |
4747

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.updatesavedobject.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Save existing index pattern. Will attempt to merge differences if there are conf
99
<b>Signature:</b>
1010

1111
```typescript
12-
updateSavedObject(indexPattern: IndexPattern, saveAttempts?: number): Promise<void | Error>;
12+
updateSavedObject(indexPattern: IndexPattern, saveAttempts?: number, ignoreErrors?: boolean): Promise<void | Error>;
1313
```
1414

1515
## Parameters
@@ -18,6 +18,7 @@ updateSavedObject(indexPattern: IndexPattern, saveAttempts?: number): Promise<vo
1818
| --- | --- | --- |
1919
| indexPattern | <code>IndexPattern</code> | |
2020
| saveAttempts | <code>number</code> | |
21+
| ignoreErrors | <code>boolean</code> | |
2122

2223
<b>Returns:</b>
2324

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern._constructor_.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Constructs a new instance of the `IndexPattern` class
99
<b>Signature:</b>
1010

1111
```typescript
12-
constructor({ spec, savedObjectsClient, fieldFormats, shortDotsEnable, metaFields, }: IndexPatternDeps);
12+
constructor({ spec, fieldFormats, shortDotsEnable, metaFields, }: IndexPatternDeps);
1313
```
1414

1515
## Parameters
1616

1717
| Parameter | Type | Description |
1818
| --- | --- | --- |
19-
| { spec, savedObjectsClient, fieldFormats, shortDotsEnable, metaFields, } | <code>IndexPatternDeps</code> | |
19+
| { spec, fieldFormats, shortDotsEnable, metaFields, } | <code>IndexPatternDeps</code> | |
2020

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export declare class IndexPattern implements IIndexPattern
1414
1515
| Constructor | Modifiers | Description |
1616
| --- | --- | --- |
17-
| [(constructor)({ spec, savedObjectsClient, fieldFormats, shortDotsEnable, metaFields, })](./kibana-plugin-plugins-data-server.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
17+
| [(constructor)({ spec, fieldFormats, shortDotsEnable, metaFields, })](./kibana-plugin-plugins-data-server.indexpattern._constructor_.md) | | Constructs a new instance of the <code>IndexPattern</code> class |
1818
1919
## Properties
2020
@@ -53,7 +53,6 @@ export declare class IndexPattern implements IIndexPattern
5353
| [getTimeField()](./kibana-plugin-plugins-data-server.indexpattern.gettimefield.md) | | |
5454
| [isTimeBased()](./kibana-plugin-plugins-data-server.indexpattern.istimebased.md) | | |
5555
| [isTimeNanosBased()](./kibana-plugin-plugins-data-server.indexpattern.istimenanosbased.md) | | |
56-
| [popularizeField(fieldName, unit)](./kibana-plugin-plugins-data-server.indexpattern.popularizefield.md) | | |
5756
| [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-server.indexpattern.removescriptedfield.md) | | Remove scripted field from field list |
5857
| [toSpec()](./kibana-plugin-plugins-data-server.indexpattern.tospec.md) | | |
5958

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpattern.popularizefield.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ describe('IndexPattern', () => {
8989

9090
describe('api', () => {
9191
test('should have expected properties', () => {
92-
expect(indexPattern).toHaveProperty('popularizeField');
9392
expect(indexPattern).toHaveProperty('getScriptedFields');
9493
expect(indexPattern).toHaveProperty('getNonScriptedFields');
9594
expect(indexPattern).toHaveProperty('addScriptedField');
@@ -241,50 +240,4 @@ describe('IndexPattern', () => {
241240
expect(restoredPattern.fieldFormatMap.bytes instanceof MockFieldFormatter).toEqual(true);
242241
});
243242
});
244-
245-
describe('popularizeField', () => {
246-
test('should increment the popularity count by default', () => {
247-
indexPattern.fields.forEach(async (field) => {
248-
const oldCount = field.count || 0;
249-
250-
await indexPattern.popularizeField(field.name);
251-
252-
expect(field.count).toEqual(oldCount + 1);
253-
});
254-
});
255-
256-
test('should increment the popularity count', () => {
257-
indexPattern.fields.forEach(async (field) => {
258-
const oldCount = field.count || 0;
259-
const incrementAmount = 4;
260-
261-
await indexPattern.popularizeField(field.name, incrementAmount);
262-
263-
expect(field.count).toEqual(oldCount + incrementAmount);
264-
});
265-
});
266-
267-
test('should decrement the popularity count', () => {
268-
indexPattern.fields.forEach(async (field) => {
269-
const oldCount = field.count || 0;
270-
const incrementAmount = 4;
271-
const decrementAmount = -2;
272-
273-
await indexPattern.popularizeField(field.name, incrementAmount);
274-
await indexPattern.popularizeField(field.name, decrementAmount);
275-
276-
expect(field.count).toEqual(oldCount + incrementAmount + decrementAmount);
277-
});
278-
});
279-
280-
test('should not go below 0', () => {
281-
indexPattern.fields.forEach(async (field) => {
282-
const decrementAmount = -Number.MAX_VALUE;
283-
284-
await indexPattern.popularizeField(field.name, decrementAmount);
285-
286-
expect(field.count).toEqual(0);
287-
});
288-
});
289-
});
290243
});

src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,18 @@ export class IndexPattern implements IIndexPattern {
7474
public metaFields: string[];
7575
// savedObject version
7676
public version: string | undefined;
77-
private savedObjectsClient: SavedObjectsClientCommon;
7877
public sourceFilters?: SourceFilter[];
7978
private originalSavedObjectBody: SavedObjectBody = {};
8079
private shortDotsEnable: boolean = false;
8180
private fieldFormats: FieldFormatsStartCommon;
8281

8382
constructor({
8483
spec = {},
85-
savedObjectsClient,
8684
fieldFormats,
8785
shortDotsEnable = false,
8886
metaFields = [],
8987
}: IndexPatternDeps) {
9088
// set dependencies
91-
this.savedObjectsClient = savedObjectsClient;
9289
this.fieldFormats = fieldFormats;
9390
// set config
9491
this.shortDotsEnable = shortDotsEnable;
@@ -267,39 +264,6 @@ export class IndexPattern implements IIndexPattern {
267264
}
268265
}
269266

270-
async popularizeField(fieldName: string, unit = 1) {
271-
/**
272-
* This function is just used by Discover and it's high likely to be removed in the near future
273-
* It doesn't use the save function to skip the error message that's displayed when
274-
* a user adds several columns in a higher frequency that the changes can be persisted to ES
275-
* resulting in 409 errors
276-
*/
277-
if (!this.id) return;
278-
const field = this.fields.getByName(fieldName);
279-
if (!field) {
280-
return;
281-
}
282-
const count = Math.max((field.count || 0) + unit, 0);
283-
if (field.count === count) {
284-
return;
285-
}
286-
field.count = count;
287-
288-
try {
289-
const res = await this.savedObjectsClient.update(
290-
'index-pattern',
291-
this.id,
292-
this.getAsSavedObjectBody(),
293-
{
294-
version: this.version,
295-
}
296-
);
297-
this.version = res.version;
298-
} catch (e) {
299-
// no need for an error message here
300-
}
301-
}
302-
303267
getNonScriptedFields() {
304268
return [...this.fields.getAll().filter((field) => !field.scripted)];
305269
}

0 commit comments

Comments
 (0)