Support for single global changes feed #25
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch adds support for a single global changes feed (it also includes my previous patch for conservative collection name derivation, although that is trivial to separate).
The global feed is enabled like:
When the single global feed is enabled, the way collection change handlers are registered is changed. (Whether they are registered has not been changed, and is still governed by the
global_changesor individual collectionchangessetting.)When single feed is enabled, each collection handler will be registered with a single changes feed.
Each collection also supports a
local_filterirrespective of the single feed. Thislocal_filterfunction can be used to, you guessed it, filter change results from the changes feed. When coupled with the single changes feed this allows each collection to only observe relevant changes. When single feed is enabled, a default local filter is installed which does this (so if you follow standard conventions you should be able to just enablesingle_feed).Default single_feed local_filter:
Example of custom local_filter:
On a technical note, change listener registration could probably be factored out into a separate class that is reused for both the per-collection and global feed, but I wanted my changes to be minimal.