share / share/sharedb

Docs in subscribed queries are always considered to be subscribed

Open
#468 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

breaking-change documentation
Dominant language
JavaScript
Stars
6.5k
Forks
456
Avg merge
1d 5h
Merged PRs (30d)
5

Description

At the moment, when you create a subscribe query, the query will automatically pass all ops back to the client, regardless of whether it wants to be subscribed or not. This can be quite confusing:

  • a Doc that matches a subscribe query will receive 'op' events, even though doc.subscribed === false
  • calling doc.unsubscribe() will not actually stop the doc receiving 'op' events

It's possible to make this behaviour a bit more consistent in a few ways:

  • check at the server if the client doc is subscribed, and only send ops back in that case
  • make connection.get() return new instances of docs rather than cached instances (which I've personally always expected) — this would allow individual Doc instances to be unsubscribed, while query.results stay subscribed

At the very least it might be nice to error in doc.unsubscribe() if the doc matches a query (and therefore cannot be unsubscribed). It may also be nice to change doc.subscribed into a method/getter which checks if it's part of a query, to reflect its "true" state

All of the above changes would technically be breaking.

One nice, non-breaking thing we could potentially do is to just logger.warn() if unsubscribing a doc that matches a query.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/query-emitter.js at the linked operation handling, then trace connection.get(), doc.unsubscribe(), and doc.subscribed for cached documents matched by queries. The issue lists several breaking and non-breaking options, so first confirm the intended behavior with maintainers; done requires an agreed subscription model and corresponding behavior for operations and unsubscribe().

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.