Skip to content

Commit

Permalink
Refactor popuplarize function
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed May 14, 2020
1 parent 0fd5311 commit 63fa09a
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,14 @@ export class IndexPattern implements IIndexPattern {
return this.save();
}

/**
* This function is just used by Discover and it's high likely to be removed in the near future
* It doesn't use the save function to skip the error message that's displayed when
* a user adds several columns in a higher frequency that the changes can be persisted to ES
* resulting in 409 errors
*/
async popularizeField(fieldName: string, unit = 1) {
if (!this.id) return;
const field = this.fields.getByName(fieldName);
if (!field) {
return;
Expand All @@ -308,7 +315,15 @@ export class IndexPattern implements IIndexPattern {
return;
}
field.count = count;
await this.save();

try {
const res = await this.savedObjectsClient.update(type, this.id, this.prepBody(), {
version: this.version,
});
this.version = res._version;
} catch (e) {
// no need for an error message here
}
}

getNonScriptedFields() {
Expand Down

0 comments on commit 63fa09a

Please sign in to comment.