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) { d.remove({ docNumber: order[i] }, options, function (err, nr) {
if (err) { return cb(err); }
if (nr !== 1) { return cb('One remove didnt work'); } 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 d.insert({ docNumber: order[i] }, function (err) { // We need to reinsert the doc so that we keep the collection's size at n
// Time is about 70x smaller for an insert so the impact on the results is minimal // So actually we're calculating the average time taken by one insert + one remove
executeAsap(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);
}); });

@ -42,11 +42,11 @@ async.waterfall([
, async.apply(commonUtilities.removeDocs, { multi: false }, d, n, profiler) , async.apply(commonUtilities.removeDocs, { multi: false }, d, n, profiler)
// Test with multiple documents // Test with multiple documents
//, async.apply(commonUtilities.prepareDb, benchDb) , async.apply(commonUtilities.prepareDb, benchDb)
//, function (cb) { d.loadDatabase(cb); } , function (cb) { d.loadDatabase(cb); }
//, async.apply(commonUtilities.insertDocs, d, n, profiler) , async.apply(commonUtilities.insertDocs, d, n, profiler)
//, function (cb) { profiler.step('MULTI: TRUE'); return cb(); } , function (cb) { profiler.step('MULTI: TRUE'); return cb(); }
//, async.apply(commonUtilities.updateDocs, { multi: true }, d, n, profiler) , async.apply(commonUtilities.removeDocs, { multi: true }, d, n, profiler)
], function (err) { ], function (err) {
profiler.step("Benchmark finished"); profiler.step("Benchmark finished");

@ -489,15 +489,15 @@ Datastore.prototype._remove = function (query, options, cb) {
, numRemoved = 0 , numRemoved = 0
, multi , multi
, removedDocs = [] , removedDocs = []
, candidates = this.getCandidates(query)
; ;
if (typeof options === 'function') { cb = options; options = {}; } if (typeof options === 'function') { cb = options; options = {}; }
callback = cb || function () {}; callback = cb || function () {};
multi = options.multi !== undefined ? options.multi : false; multi = options.multi !== undefined ? options.multi : false;
// CHANGE
try { try {
self.getAllData().forEach(function (d) { // CHANGE candidates.forEach(function (d) {
if (model.match(d, query) && (multi || numRemoved === 0)) { if (model.match(d, query) && (multi || numRemoved === 0)) {
numRemoved += 1; numRemoved += 1;
removedDocs.push({ $$deleted: true, _id: d._id }); removedDocs.push({ $$deleted: true, _id: d._id });

Loading…
Cancel
Save