Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/middleware/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %})

Expand Down
2 changes: 2 additions & 0 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions lib/query-emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions test/client/query-subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down
Loading