Skip to content

Commit

Permalink
Feedback from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1mmy committed Dec 17, 2012
1 parent aee54f3 commit 0faaa07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 11 additions & 4 deletions packages/minimongo/minimongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,17 @@ LocalCollection.prototype.findOne = function (selector, options) {
if (arguments.length === 0)
selector = {};

// XXX disable limit here so that we can observe findOne() cursor,
// as required by markAsReactive.
// options = options || {};
// options.limit = 1;
// NOTE: by setting limit 1 here, we end up using very inefficient
// code that recomputes the whole query on each update. The upside is
// that when you reactively depend on a findOne you only get
// invalidated when the found object changes, not any object in the
// collection. Most findOne will be by id, which has a fast path, so
// this might not be a big deal. In most cases, invalidation causes
// the called to re-query anyway, so this should be a net performance
// improvement.
options = options || {};
options.limit = 1;

return this.find(selector, options).fetch()[0];
};

Expand Down
4 changes: 3 additions & 1 deletion packages/minimongo/minimongo_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,9 @@ Tinytest.add("minimongo - observe", function (test) {
c.insert({a:4});
test.equal(operations.shift(), undefined);
id = c.findOne({a:2})._id;
c.update({a:1}, {a:5});
c.update({a:1}, {a:0});
test.equal(operations.shift(), undefined);
c.update({a:0}, {a:5});
test.equal(operations.shift(), ['removed', id, 0, {a:2}]);
test.equal(operations.shift(), ['added', {a:4}, 1]);

Expand Down

0 comments on commit 0faaa07

Please sign in to comment.