Skip to content

💥 Stop polling multi-channel queries every second by default - #780

Merged
alecgibson merged 1 commit into
mainfrom
no-multi-channel-poll-interval
Nov 12, 2026
Merged

alecgibson merged 1 commit into
mainfrom
no-multi-channel-poll-interval

Conversation

@alecgibson

Copy link
Copy Markdown
Collaborator

At the moment, a subscribed query with more than one channel defaults pollInterval to 1000, so it re-runs against the database every second for as long as it's subscribed, even when nothing has changed. At Reedsy, that was ~2/3 of all our ShareDB requests.

Nothing asks for that interval. It arrived with multi-channel queries in #587, where review only suggested a pollDebounce default to batch polls. The interval catches changes that don't publish an op on any of the query's channels, which depends on how an app picks its channels, not how many there are, and a query on one channel has never had it.

This is a BREAKING CHANGE, though apps that already set pollInterval are unaffected. The pollDebounce default is unchanged, and this middleware, registered after the one that sets context.channels, restores the old interval:

backend.use('query', (context, next) => {
  if (context.channels.length > 1) context.options.pollInterval = 1000
  next()
})

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change removing automatic polling from multi-channel query subscriptions.

No open issues 🎉

What changed in this PR

This PR removes automatic one-second database polling for multi-channel query subscriptions, reducing unnecessary database load. This is a breaking default change; explicitly configured polling intervals and the existing debounce behavior remain unchanged.

Changes:

  • Default pollInterval to zero regardless of channel count.
  • Add a regression test for timer-free subscriptions and remove redundant interval overrides.
  • Document polling defaults and when an explicit interval is useful.
File Description
test/​client/​query-subscribe.js Adds timer-polling regression coverage and removes redundant overrides.
lib/​query-emitter.js Removes the multi-channel polling interval default.
lib/​backend.js Documents the purpose of pollInterval.
docs/​middleware/​actions.md Clarifies interval and debounce defaults.

Review effort: Balanced

At the moment, a subscribed query with more than one channel
[defaults][1] `pollInterval` to 1000, so it re-runs against the
database every second for as long as it's subscribed, even when
nothing has changed. At Reedsy, that was ~2/3 of all our ShareDB
requests.

Nothing asks for that interval. It arrived with multi-channel queries
in #587, where review only suggested a `pollDebounce` default to
[batch polls][2]. The interval catches changes that don't publish an
op on any of the query's channels, which depends on how an app picks
its channels, not how many there are, and a query on one channel has
never had it.

This is a **BREAKING CHANGE**, though apps that already set
`pollInterval` are unaffected. The `pollDebounce` default is unchanged,
and this middleware, registered after the one that sets
`context.channels`, restores the old interval:

```js
backend.use('query', (context, next) => {
  if (context.channels.length > 1) context.options.pollInterval = 1000
  next()
})
```

[1]: https://github.com/share/sharedb/blob/628de990e858439c1f3dbff4f65f95ef9a70d0a2/lib/query-emitter.js#L24-L31
[2]: #587 (comment)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@alecgibson
alecgibson force-pushed the no-multi-channel-poll-interval branch from 8e9f692 to 1a19691 Compare November 11, 2026 16:05
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 98.049%. remained the same — no-multi-channel-poll-interval into main

@dawidreedsy dawidreedsy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do not remember why did the polling 1000, but it seems fine without it.

@alecgibson
alecgibson merged commit 7d5180f into main Nov 12, 2026
9 checks passed
@alecgibson
alecgibson deleted the no-multi-channel-poll-interval branch November 12, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants