@@ -63,7 +63,12 @@ QueryEmitter.prototype._emitTiming = function(action, start) {
63
63
} ;
64
64
65
65
QueryEmitter . 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()
66
70
var id = op . d ;
71
+ var pollCallback = this . _defaultCallback ;
67
72
68
73
// Check if the op's id matches the query before updating the query results
69
74
// and send it through immediately if it does. The current snapshot
@@ -90,28 +95,35 @@ QueryEmitter.prototype._update = function(op) {
90
95
// that removed the doc from the query to cause the client-side computed
91
96
// list to update.
92
97
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
+ } ;
98
106
}
99
107
100
108
// Ignore if the database or user function says we don't need to poll
101
109
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
+ }
104
116
} catch ( err ) {
105
- return this . _defaultCallback ( err ) ;
117
+ return pollCallback ( err ) ;
106
118
}
107
119
if ( this . canPollDoc ) {
108
120
// We can query against only the document that was modified to see if the
109
121
// op has changed whether or not it matches the results
110
- this . queryPollDoc ( id , this . _defaultCallback ) ;
122
+ this . queryPollDoc ( id , pollCallback ) ;
111
123
} else {
112
124
// We need to do a full poll of the query, because the query uses limits,
113
125
// sorts, or something special
114
- this . queryPoll ( this . _defaultCallback ) ;
126
+ this . queryPoll ( pollCallback ) ;
115
127
}
116
128
} ;
117
129
0 commit comments