Skip to content

Commit

Permalink
toPublish and toBuffer (or staysInBuffer) can't be true at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava committed Feb 26, 2014
1 parent afc58bc commit a0cc339
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/mongo-livedata/oplog_observe_driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ _.extend(OplogObserveDriver.prototype, {
// Otherwise we might need to buffer it (only in case of limited query).
// Buffering is allowed if the buffer is not filled up yet and all matching
// docs are either in the published set or in the buffer.
var canAppendToBuffer = self._safeAppendToBuffer &&
var canAppendToBuffer = !toPublish && self._safeAppendToBuffer &&
self._unpublishedBuffer.size() < limit;

// Or if it is small enough to be safely inserted to the middle or the
// beginning of the buffer.
var canInsertIntoBuffer = maxBuffered && comparator(maxBuffered, doc) > 0;
var canInsertIntoBuffer = !toPublish && maxBuffered &&
comparator(maxBuffered, doc) > 0;

var toBuffer = canAppendToBuffer || canInsertIntoBuffer;

Expand Down Expand Up @@ -358,8 +359,8 @@ _.extend(OplogObserveDriver.prototype, {
var toPublish = comparator(newDoc, maxPublished) < 0;

// or stays in buffer even after the change
var staysInBuffer = self._safeAppendToBuffer ||
(maxBuffered && comparator(newDoc, maxBuffered) < 0);
var staysInBuffer = (! toPublish && self._safeAppendToBuffer) ||
(!toPublish && maxBuffered && comparator(newDoc, maxBuffered) < 0);

if (toPublish) {
self._addPublished(id, newDoc);
Expand Down

0 comments on commit a0cc339

Please sign in to comment.