mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
optimize paused remove({}) which oplog uses
This commit is contained in:
@@ -563,10 +563,31 @@ LocalCollection.prototype.insert = function (doc, callback) {
|
||||
|
||||
LocalCollection.prototype.remove = function (selector, callback) {
|
||||
var self = this;
|
||||
var remove = [];
|
||||
|
||||
var queriesToRecompute = [];
|
||||
// Easy special case: if we're not calling observeChanges callbacks and we're
|
||||
// not saving originals and we got asked to remove everything, then just empty
|
||||
// everything directly.
|
||||
if (self.paused && !self._savedOriginals && EJSON.equals(selector, {})) {
|
||||
var result = self._docs.size();
|
||||
self._docs.clear();
|
||||
_.each(self.queries, function (query) {
|
||||
if (query.ordered) {
|
||||
query.results = [];
|
||||
} else {
|
||||
query.results.clear();
|
||||
}
|
||||
});
|
||||
if (callback) {
|
||||
Meteor.defer(function () {
|
||||
callback(null, result);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var matcher = new Minimongo.Matcher(selector, self);
|
||||
var queriesToRecompute = [];
|
||||
var remove = [];
|
||||
|
||||
// Avoid O(n) for "remove a single doc by ID".
|
||||
var specificIds = LocalCollection._idsMatchedBySelector(selector);
|
||||
@@ -616,7 +637,7 @@ LocalCollection.prototype.remove = function (selector, callback) {
|
||||
LocalCollection._recomputeResults(query);
|
||||
});
|
||||
self._observeQueue.drain();
|
||||
var result = remove.length;
|
||||
result = remove.length;
|
||||
if (callback)
|
||||
Meteor.defer(function () {
|
||||
callback(null, result);
|
||||
|
||||
@@ -2565,6 +2565,14 @@ Tinytest.add("minimongo - pause", function (test) {
|
||||
test.equal(operations.shift(), ['changed', {a:3}, 0, {a:1}]);
|
||||
test.length(operations, 0);
|
||||
|
||||
// test special case for remove({})
|
||||
c.pauseObservers();
|
||||
test.equal(c.remove({}), 1);
|
||||
test.length(operations, 0);
|
||||
c.resumeObservers();
|
||||
test.equal(operations.shift(), ['removed', 1, 0, {a:3}]);
|
||||
test.length(operations, 0);
|
||||
|
||||
h.stop();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user