Skip to content

Commit

Permalink
[Discover] Catch error when popularizeField fails (#62402)
Browse files Browse the repository at this point in the history
* Refactor index_patterns popularize function, so no message is displayed to the user
  • Loading branch information
kertal authored May 14, 2020
1 parent d2381eb commit 02a2d07
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ export class IndexPattern implements IIndexPattern {
}

async popularizeField(fieldName: string, unit = 1) {
/**
* 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
*/
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 02a2d07

Please sign in to comment.