Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP first crack at _suppress_initial support #338

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/cache/ObservableCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
}
Expand Down
1 change: 1 addition & 0 deletions lib/mongo/PollingObserveDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/mongo/RedisOplogObserveDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions lib/mongo/observeChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down