diff --git a/docs/middleware/actions.md b/docs/middleware/actions.md index 658a9174..0f64287e 100644 --- a/docs/middleware/actions.md +++ b/docs/middleware/actions.md @@ -139,7 +139,7 @@ This action has these additional `context` properties: `options` -- Object -> The query [options]({{ site.baseurl }}{% link api/connection.md %}#createfetchquery). Any `fields`, `pollInterval` or `pollDebounce` sent by the client has already been removed. Set `pollInterval` or `pollDebounce` here to control how often this query polls the database. +> The query [options]({{ site.baseurl }}{% link api/connection.md %}#createfetchquery). Any `fields`, `pollInterval` or `pollDebounce` sent by the client has already been removed. Set `pollInterval` or `pollDebounce` here to control how often this query polls the database. Both default to 0, except that `pollDebounce` defaults to 1000 ms for a query on more than one channel. `db` -- [DB]({{ site.baseurl }}{% link adapters/database.md %}) diff --git a/lib/backend.js b/lib/backend.js index 82fa62b4..3d883ed8 100644 --- a/lib/backend.js +++ b/lib/backend.js @@ -661,6 +661,8 @@ Backend.prototype.queryFetch = function(agent, index, query, options, callback) // pollDebounce: Minimum delay between subsequent database polls. This is // used to batch updates to reduce load on the database at the expense of // liveness +// pollInterval: Maximum delay between subsequent database polls. Set this to +// pick up changes that don't publish an op on the query's channels Backend.prototype.querySubscribe = function(agent, index, query, options, callback) { var start = Date.now(); var backend = this; diff --git a/lib/query-emitter.js b/lib/query-emitter.js index 335ba6a5..d69f5d2e 100644 --- a/lib/query-emitter.js +++ b/lib/query-emitter.js @@ -27,8 +27,7 @@ function QueryEmitter(request, streams, ids, extra) { streams.length > 1 ? 1000 : 0; this.pollInterval = (typeof this.options.pollInterval === 'number') ? this.options.pollInterval : - (typeof this.db.pollInterval === 'number') ? this.db.pollInterval : - streams.length > 1 ? 1000 : 0; + (typeof this.db.pollInterval === 'number') ? this.db.pollInterval : 0; this._polling = false; this._pendingPoll = null; diff --git a/test/client/query-subscribe.js b/test/client/query-subscribe.js index 0fba3d75..cd74addb 100644 --- a/test/client/query-subscribe.js +++ b/test/client/query-subscribe.js @@ -127,7 +127,6 @@ module.exports = function(options) { it('does not duplicate messages', function(done) { var connection = this.backend.connect(); - this.backend.db.pollInterval = 0; this.backend.db.pollDebounce = 0; var count = 0; var query = connection.createSubscribeQuery( @@ -156,6 +155,19 @@ module.exports = function(options) { }); }); + it('does not poll the database on a timer', function(done) { + var clock = util.useFakeTimers(); + var connection = this.backend.connect(); + var db = this.backend.db; + connection.createSubscribeQuery('dogs', this.matchAllDbQuery, null, function(err) { + if (err) return done(err); + sinon.spy(db, 'queryPoll'); + clock.tick(5000); + expect(db.queryPoll.called).to.be.false; + done(); + }); + }); + commonCustomChannelsErrorHandlingTests(); commonTests(options); }); @@ -739,7 +751,6 @@ function commonTests(options) { var clock = util.useFakeTimers(); var connection = this.backend.connect(); var db = this.backend.db; - db.pollInterval = 0; sinon.spy(db, 'queryPoll'); connection.createSubscribeQuery('dogs', this.matchAllDbQuery, {pollInterval: 50}, function(err) { if (err) return done(err);