Benchmark for removes works

pull/2/head
Louis Chatriot 12 years ago
parent 123ef7e8db
commit ba03cb24e6
  1. 5
      benchmarks/commonUtilities.js
  2. 10
      benchmarks/remove.js
  3. 4
      lib/datastore.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);
});

@ -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");

@ -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 });

Loading…
Cancel
Save