diff --git a/lib/cache/ObservableCollection.js b/lib/cache/ObservableCollection.js index 12e29094..2a93fb21 100644 --- a/lib/cache/ObservableCollection.js +++ b/lib/cache/ObservableCollection.js @@ -27,11 +27,11 @@ export default class ObservableCollection { * Instantiate the collection * @param {*} param */ - constructor({ multiplexer, matcher, sorter, cursorDescription }) { + constructor({ multiplexer, matcher, sorter, cursorDescription, _suppress_initial }) { this.multiplexer = multiplexer; this.matcher = matcher; this.cursorDescription = cursorDescription; - + this._suppress_initial = _suppress_initial; this.collectionName = this.cursorDescription.collectionName; this.collection = Mongo.Collection.__getCollectionByName( cursorDescription.collectionName @@ -164,6 +164,10 @@ export default class ObservableCollection { * Performs the initial search then puts them into the store. */ init() { + if (this._suppress_initial) { + this.multiplexer.ready(); + return; + } if (this.__isInitialized) { return; // silently do nothing. } diff --git a/lib/mongo/PollingObserveDriver.js b/lib/mongo/PollingObserveDriver.js index 1271079f..ab24713e 100644 --- a/lib/mongo/PollingObserveDriver.js +++ b/lib/mongo/PollingObserveDriver.js @@ -57,6 +57,7 @@ function forEachTrigger(cursorDescription, triggerCallback) { export default function PollingObserveDriver(options) { var self = this; + this.options = options; self._cursorDescription = options.cursorDescription; self._mongoHandle = options.mongoHandle; self._ordered = options.ordered; diff --git a/lib/mongo/RedisOplogObserveDriver.js b/lib/mongo/RedisOplogObserveDriver.js index a19f3742..b52f21c8 100644 --- a/lib/mongo/RedisOplogObserveDriver.js +++ b/lib/mongo/RedisOplogObserveDriver.js @@ -35,6 +35,7 @@ export default class RedisOplogObserveDriver { // TODO send by object this.observableCollection = new ObservableCollection({ + _suppress_initial: this.options._suppress_initial, multiplexer, matcher, sorter, diff --git a/lib/mongo/observeChanges.js b/lib/mongo/observeChanges.js index 270d532d..8ea5af03 100644 --- a/lib/mongo/observeChanges.js +++ b/lib/mongo/observeChanges.js @@ -41,8 +41,15 @@ export default function(cursorDescription, ordered, callbacks) { // new query), so no other calls to this function can interleave with it. Meteor._noYieldsAllowed(function() { + if (_.has(self._observeMultiplexers, observeKey)) { multiplexer = self._observeMultiplexers[observeKey]; + if (multiplexer.observeDriver && multiplexer.observeDriver._suppress_initial !== callbacks._suppress_initial) { + multiplexer.observeDriver._suppress_initial = callbacks._suppress_initial; + if (!multiplexer.observeDriver._suppress_initial) { + multiplexer.observeDriver.observableCollection.init(); + } + } } else { firstHandle = true; // Create a new ObserveMultiplexer. @@ -120,7 +127,9 @@ export default function(cursorDescription, ordered, callbacks) { ? RedisOplogObserveDriver : PollingObserveDriver; + try { observeDriver = new driverClass({ + _suppress_initial: callbacks._suppress_initial, cursorDescription: cursorDescription, mongoHandle: self, multiplexer: multiplexer, @@ -133,6 +142,11 @@ export default function(cursorDescription, ordered, callbacks) { }); // This field is only set for use in tests. multiplexer._observeDriver = observeDriver; + } + catch (e) { + console.error(e); + delete self._observeMultiplexers[observeKey]; + } } // Blocks until the initial adds have been sent.