Skip to content

Commit

Permalink
Stop using weird "curiousity" nomenclature.
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Dec 3, 2013
1 parent 24913f8 commit 2f5ed9a
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/mongo-livedata/oplog.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ MongoConnection.prototype._observeChangesWithOplog = function (
var published = new IdMap;
var selector = LocalCollection._compileSelector(cursorDescription.selector);

// XXX eliminate "curious" name
var curiousity = new IdMap;
var needToFetch = new IdMap;
var currentlyFetching = new IdMap;

var add = function (doc) {
Expand Down Expand Up @@ -67,17 +66,17 @@ MongoConnection.prototype._observeChangesWithOplog = function (
}
};

var beCurious = function () {
var fetchModifiedDocuments = function () {
phase = PHASE.FETCHING;
while (!curiousity.isEmpty()) {
while (!needToFetch.isEmpty()) {
if (phase !== PHASE.FETCHING)
throw new Error("Surprising phase in beCurious: " + phase);
throw new Error("Surprising phase in fetchModifiedDocuments: " + phase);

var futures = [];
currentlyFetching = curiousity;
curiousity = new IdMap;
currentlyFetching = needToFetch;
needToFetch = new IdMap;
currentlyFetching.each(function (cacheKey, id) {
// Run each until they yield. This implies that curiousity should not be
// Run each until they yield. This implies that needToFetch will not be
// updated during this loop.
Fiber(function () {
var f = new Future;
Expand Down Expand Up @@ -111,23 +110,23 @@ MongoConnection.prototype._observeChangesWithOplog = function (

var oplogEntryHandlers = {};
oplogEntryHandlers[PHASE.INITIALIZING] = function (op) {
curiousity.set(idForOp(op), op.ts.toString());
needToFetch.set(idForOp(op), op.ts.toString());
};
oplogEntryHandlers[PHASE.FETCHING] = function (op) {
var id = idForOp(op);
// We can handle non-modify changes to things that we aren't fetching,
// directly.
};
// We can use the same handler for STEADY and FETCHING; the main difference is
// that FETCHING has non-empty currentlyFetching and/or curiousity.
// that FETCHING has non-empty currentlyFetching and/or needToFetch.
oplogEntryHandlers[PHASE.STEADY] = function (op) {
var id = idForOp(op);
// If we're already fetching this one, or about to, we can't optimize; make
// sure that we fetch it again if necessary.
if (currentlyFetching.has(id) || curiousity.has(id)) {
if (currentlyFetching.has(id) || needToFetch.has(id)) {
if (phase !== PHASE.FETCHING)
throw Error("map not empty during steady phase");
curiousity.set(id, op.ts.toString());
needToFetch.set(id, op.ts.toString());
return;
}

Expand Down Expand Up @@ -167,9 +166,9 @@ MongoConnection.prototype._observeChangesWithOplog = function (
return;
}

curiousity.set(id, op.ts.toString());
needToFetch.set(id, op.ts.toString());
if (phase === PHASE.STEADY)
beCurious();
fetchModifiedDocuments();
return;
}
} else {
Expand Down Expand Up @@ -219,11 +218,11 @@ MongoConnection.prototype._observeChangesWithOplog = function (
if (phase !== PHASE.INITIALIZING)
throw Error("Phase unexpectedly " + phase);

if (curiousity.isEmpty()) {
if (needToFetch.isEmpty()) {
beSteady();
} else {
phase = PHASE.FETCHING;
Meteor.defer(beCurious);
Meteor.defer(fetchModifiedDocuments);
}

return {
Expand Down

0 comments on commit 2f5ed9a

Please sign in to comment.