Skip to content

Commit

Permalink
Remove broken check for bulk write support (#1929)
Browse files Browse the repository at this point in the history
* Remove broken check for bulk write support

* Check that batch is not empty before trying to execute it
  • Loading branch information
brent-hoover authored and kieckhafer committed Mar 6, 2017
1 parent 838dd08 commit ac9a3d1
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions imports/plugins/included/inventory/server/methods/statusChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,16 @@ Meteor.methods({

// insert backorder
let i = 0;
const batch = Inventory.rawCollection().initializeUnorderedBulkOp();
if (batch) {
while (i < backOrderQty) {
const id = Inventory._makeNewID();
batch.insert(Object.assign({ _id: id }, newReservation));
i++;
}

// check if we support bulk operations
const currentBatch = Inventory._collection.rawCollection().currentBatch;

if (currentBatch && currentBatch.operations && currentBatch.operations.length > 0) {
const batch = Inventory._collection.rawCollection().initializeUnorderedBulkOp();
if (batch) {
while (i < backOrderQty) {
const id = Inventory._makeNewID();
batch.insert(Object.assign({ _id: id }, newReservation));
i++;
}

const execute = Meteor.wrapAsync(batch.execute, batch);
const execute = Meteor.wrapAsync(batch.execute, batch);
if (batch.length) {
const inventoryBackorder = execute();
const inserted = inventoryBackorder.nInserted;
Logger.debug(`created ${inserted} backorder records for product ${newReservation.productId}, variant ${newReservation.variantId}`);
Expand Down

0 comments on commit ac9a3d1

Please sign in to comment.