Skip to content

Commit

Permalink
Revert "added version to saved object bulk creation"
Browse files Browse the repository at this point in the history
This reverts commit d4820e1.
  • Loading branch information
gmmorris committed Aug 18, 2020
1 parent 7bd360c commit caa1834
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
33 changes: 2 additions & 31 deletions src/core/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,8 @@ describe('SavedObjectsRepository', () => {
{ method, _index = expect.any(String), getId = () => expect.any(String) }
) => {
const body = [];
for (const { type, id, if_primary_term: ifPrimaryTerm, if_seq_no: ifSeqNo } of objects) {
body.push({
[method]: {
_index,
_id: getId(type, id),
...(ifPrimaryTerm && ifSeqNo
? { if_primary_term: expect.any(Number), if_seq_no: expect.any(Number) }
: {}),
},
});
for (const { type, id } of objects) {
body.push({ [method]: { _index, _id: getId(type, id) } });
body.push(expect.any(Object));
}
expect(client.bulk).toHaveBeenCalledWith(
Expand Down Expand Up @@ -533,27 +525,6 @@ describe('SavedObjectsRepository', () => {
expectClientCallArgsAction([obj1, obj2], { method: 'index' });
});

it(`should use the ES index method with version if ID and version are defined and overwrite=true`, async () => {
await bulkCreateSuccess(
[
{
...obj1,
version: mockVersion,
},
obj2,
],
{ overwrite: true }
);

const obj1WithSeq = {
...obj1,
if_seq_no: mockVersionProps._seq_no,
if_primary_term: mockVersionProps._primary_term,
};

expectClientCallArgsAction([obj1WithSeq, obj2], { method: 'index' });
});

it(`should use the ES create method if ID is defined and overwrite=false`, async () => {
await bulkCreateSuccess([obj1, obj2]);
expectClientCallArgsAction([obj1, obj2], { method: 'create' });
Expand Down
10 changes: 1 addition & 9 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,7 @@ export class SavedObjectsRepository {

let savedObjectNamespace;
let savedObjectNamespaces;
let versionProperties;
const {
esRequestIndex,
object: { version, ...object },
method,
} = expectedBulkGetResult.value;
const { esRequestIndex, object, method } = expectedBulkGetResult.value;
if (esRequestIndex !== undefined) {
const indexFound = bulkGetResponse?.statusCode !== 404;
const actualResult = indexFound ? bulkGetResponse?.body.docs[esRequestIndex] : undefined;
Expand All @@ -369,14 +364,12 @@ export class SavedObjectsRepository {
};
}
savedObjectNamespaces = getSavedObjectNamespaces(namespace, docFound && actualResult);
versionProperties = getExpectedVersionProperties(version, actualResult);
} else {
if (this._registry.isSingleNamespace(object.type)) {
savedObjectNamespace = namespace;
} else if (this._registry.isMultiNamespace(object.type)) {
savedObjectNamespaces = getSavedObjectNamespaces(namespace);
}
versionProperties = getExpectedVersionProperties(version);
}

const expectedResult = {
Expand All @@ -401,7 +394,6 @@ export class SavedObjectsRepository {
[method]: {
_id: expectedResult.rawMigratedDoc._id,
_index: this.getIndexForType(object.type),
...(overwrite && versionProperties),
},
},
expectedResult.rawMigratedDoc._source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export interface SavedObjectsBulkCreateObject<T = unknown> {
id?: string;
type: string;
attributes: T;
version?: string;
references?: SavedObjectReference[];
/** {@inheritDoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
Expand Down

0 comments on commit caa1834

Please sign in to comment.