Skip to content

Commit

Permalink
Benchmark for removes works
Browse files Browse the repository at this point in the history
  • Loading branch information
louischatriot committed Jun 1, 2013
1 parent 123ef7e commit ba03cb2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions benchmarks/commonUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions lib/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit ba03cb2

Please sign in to comment.