@@ -63,7 +63,12 @@ QueryEmitter.prototype._emitTiming = function(action, start) {
6363} ;
6464
6565QueryEmitter . prototype . _update = function ( op ) {
66+ // Note that `op` should not be projected or sanitized yet. It's possible for
67+ // a query to filter on a field that's not in the projection. skipPoll checks
68+ // to see if an op could possibly affect a query, so it should get passed the
69+ // full op. The onOp listener function must call backend.sanitizeOp()
6670 var id = op . d ;
71+ var pollCallback = this . _defaultCallback ;
6772
6873 // Check if the op's id matches the query before updating the query results
6974 // and send it through immediately if it does. The current snapshot
@@ -90,28 +95,35 @@ QueryEmitter.prototype._update = function(op) {
9095 // that removed the doc from the query to cause the client-side computed
9196 // list to update.
9297 if ( this . ids . indexOf ( id ) !== - 1 ) {
93- // Note that this op is not projected or sanitized yet. It's possible for a
94- // query to filter on a field that's not in the projection. skipPoll checks
95- // to see if an op could possibly affect a query, so it should get passed
96- // the full op. The onOp listener function must call backend.sanitizeOp()
97- this . onOp ( op ) ;
98+ var emitter = this ;
99+ pollCallback = function ( err ) {
100+ // Send op regardless of polling error. Clients handle subscription to ops
101+ // on the documents that currently match query results independently from
102+ // updating which docs match the query
103+ emitter . onOp ( op ) ;
104+ if ( err ) emitter . onError ( err ) ;
105+ } ;
98106 }
99107
100108 // Ignore if the database or user function says we don't need to poll
101109 try {
102- if ( this . db . skipPoll ( this . collection , id , op , this . query ) ) return this . _defaultCallback ( ) ;
103- if ( this . skipPoll ( this . collection , id , op , this . query ) ) return this . _defaultCallback ( ) ;
110+ if (
111+ this . db . skipPoll ( this . collection , id , op , this . query ) ||
112+ this . skipPoll ( this . collection , id , op , this . query )
113+ ) {
114+ return pollCallback ( ) ;
115+ }
104116 } catch ( err ) {
105- return this . _defaultCallback ( err ) ;
117+ return pollCallback ( err ) ;
106118 }
107119 if ( this . canPollDoc ) {
108120 // We can query against only the document that was modified to see if the
109121 // op has changed whether or not it matches the results
110- this . queryPollDoc ( id , this . _defaultCallback ) ;
122+ this . queryPollDoc ( id , pollCallback ) ;
111123 } else {
112124 // We need to do a full poll of the query, because the query uses limits,
113125 // sorts, or something special
114- this . queryPoll ( this . _defaultCallback ) ;
126+ this . queryPoll ( pollCallback ) ;
115127 }
116128} ;
117129
0 commit comments