diff --git a/benchmarks/commonUtilities.js b/benchmarks/commonUtilities.js index 3d6f800..f812a54 100644 --- a/benchmarks/commonUtilities.js +++ b/benchmarks/commonUtilities.js @@ -186,9 +186,10 @@ module.exports.removeDocs = function (options, d, n, profiler, cb) { } d.remove({ docNumber: order[i] }, options, function (err, nr) { + if (err) { return cb(err); } if (nr !== 1) { return cb('One remove didnt work'); } - d.insert({ docNumber: order[i] }, function (err) { // Reinserting just removed document so that the collection size doesn't change - // Time is about 70x smaller for an insert so the impact on the results is minimal + d.insert({ docNumber: order[i] }, function (err) { // We need to reinsert the doc so that we keep the collection's size at n + // So actually we're calculating the average time taken by one insert + one remove executeAsap(function () { runFrom(i + 1); }); diff --git a/benchmarks/remove.js b/benchmarks/remove.js index 4c8f5d4..754c3b2 100644 --- a/benchmarks/remove.js +++ b/benchmarks/remove.js @@ -42,11 +42,11 @@ async.waterfall([ , async.apply(commonUtilities.removeDocs, { multi: false }, d, n, profiler) // Test with multiple documents -//, async.apply(commonUtilities.prepareDb, benchDb) -//, function (cb) { d.loadDatabase(cb); } -//, async.apply(commonUtilities.insertDocs, d, n, profiler) -//, function (cb) { profiler.step('MULTI: TRUE'); return cb(); } -//, async.apply(commonUtilities.updateDocs, { multi: true }, d, n, profiler) +, async.apply(commonUtilities.prepareDb, benchDb) +, function (cb) { d.loadDatabase(cb); } +, async.apply(commonUtilities.insertDocs, d, n, profiler) +, function (cb) { profiler.step('MULTI: TRUE'); return cb(); } +, async.apply(commonUtilities.removeDocs, { multi: true }, d, n, profiler) ], function (err) { profiler.step("Benchmark finished"); diff --git a/lib/datastore.js b/lib/datastore.js index d607f1f..0863bab 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -489,15 +489,15 @@ Datastore.prototype._remove = function (query, options, cb) { , numRemoved = 0 , multi , removedDocs = [] + , candidates = this.getCandidates(query) ; if (typeof options === 'function') { cb = options; options = {}; } callback = cb || function () {}; multi = options.multi !== undefined ? options.multi : false; - // CHANGE try { - self.getAllData().forEach(function (d) { // CHANGE + candidates.forEach(function (d) { if (model.match(d, query) && (multi || numRemoved === 0)) { numRemoved += 1; removedDocs.push({ $$deleted: true, _id: d._id });