-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cozy-pouch-link): Add startReplicationWithDebounce()
method
#1553
Conversation
We want to be able to debounce calls to `startReplication()` This commit adds the `startReplicationWithDebounce()` method that is responsible to debounce the call of `startReplication()` by a specific delay The debounce delay can be configured using the CozyPouchLink constructor's `syncDebounceDelayInMs` option Calling the `startReplication()` will cancel debounced calls and immediately execute the replication
@@ -11,6 +11,7 @@ import defaults from 'lodash/defaults' | |||
import mapValues from 'lodash/mapValues' | |||
import zipWith from 'lodash/zipWith' | |||
import get from 'lodash/get' | |||
import debounce from 'lodash/debounce' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really worth the import compared to a simple setTimeout ? Is it because of the .cancel feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this choice mainly because I have more trust in a widely used utility library than in our code 😄 (but also because we already includes lodash in all our projects, my choice would have been different otherwise)
@@ -285,15 +311,26 @@ class PouchLink extends CozyLink { | |||
* @returns {void} | |||
*/ | |||
startReplication() { | |||
this.client.emit('pouchlink:sync:start') | |||
this.startReplicationDebounced.cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means each new replication call will reset the debounce timer, right?
I wonder if we should rather have a mechanism where the timer is not reset, and new function calls are simply ignored.
In the current implementation, we might never replicate (or greatly delay) if we receive continuous realtime events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this by adding a maxdelay parameter here: 0c9557c
In previous commit we added the possibility to debounce the `startReplication()` method and to configure the debounce delay with `syncDebounceDelayInMs` parameter This may be problematic as we expect to call this from realtime events that may, in some rare scenario, occur too often to trigger a single replication due to the debounce To prevent this we add the `syncDebounceMaxDelayInMs` parameter that will ensure that `startReplication()` is called when the max delay is reached even if realtime events trigger the debounce for too long
In cozy/cozy-client#1553 we introduced a new `startReplicationWithDebounce()` method that will be used by the SearchEngine from cozy-dataproxy We want to fine tune this method's behavior by configuring its debounce timings By doing so, all realtime events on searched doctypes will trigger a replication with a 30s debounce and in the case of many multiple realtime events, the maximum debounce would be of 10min Related PR: cozy/cozy-client#1553
`cozy-pouch-link` has been upgraded to `50.3.1` in order to retrieve `startReplicationWithDebounce()` method implementation `cozy-client` has been upgraded to `50.3.1` in order to retrieve some typing fixes Related PR: cozy/cozy-client#1553 Related PR: cozy/cozy-client#1556
`cozy-pouch-link` has been upgraded to `50.3.1` in order to retrieve `startReplicationWithDebounce()` method implementation `cozy-client` has been upgraded to `50.3.1` in order to retrieve some typing fixes Related PR: cozy/cozy-client#1553 Related PR: cozy/cozy-client#1556
`cozy-pouch-link` has been upgraded to `50.3.1` in order to retrieve `startReplicationWithDebounce()` method implementation `cozy-client` has been upgraded to `50.3.1` in order to retrieve some typing fixes Related PR: cozy/cozy-client#1553 Related PR: cozy/cozy-client#1556
In cozy/cozy-client#1553 we introduced a new `startReplicationWithDebounce()` method that will be used by the SearchEngine from cozy-dataproxy We want to fine tune this method's behavior by configuring its debounce timings By doing so, all realtime events on searched doctypes will trigger a replication with a 30s debounce and in the case of many multiple realtime events, the maximum debounce would be of 10min Related PR: cozy/cozy-client#1553
`cozy-pouch-link` has been upgraded to `50.3.1` in order to retrieve `startReplicationWithDebounce()` method implementation `cozy-client` has been upgraded to `50.3.1` in order to retrieve some typing fixes Related PR: cozy/cozy-client#1553 Related PR: cozy/cozy-client#1556
In cozy/cozy-client#1553 we introduced a new `startReplicationWithDebounce()` method that will be used by the SearchEngine from cozy-dataproxy We want to fine tune this method's behavior by configuring its debounce timings By doing so, all realtime events on searched doctypes will trigger a replication with a 30s debounce and in the case of many multiple realtime events, the maximum debounce would be of 10min Related PR: cozy/cozy-client#1553
`cozy-pouch-link` has been upgraded to `50.3.1` in order to retrieve `startReplicationWithDebounce()` method implementation `cozy-client` has been upgraded to `50.3.1` in order to retrieve some typing fixes Related PR: cozy/cozy-client#1553 Related PR: cozy/cozy-client#1556
In cozy/cozy-client#1553 we introduced a new `startReplicationWithDebounce()` method that will be used by the SearchEngine from cozy-dataproxy We want to fine tune this method's behavior by configuring its debounce timings By doing so, all realtime events on searched doctypes will trigger a replication with a 30s debounce and in the case of many multiple realtime events, the maximum debounce would be of 10min Related PR: cozy/cozy-client#1553
`cozy-pouch-link` has been upgraded to `50.3.1` in order to retrieve `startReplicationWithDebounce()` method implementation `cozy-client` has been upgraded to `50.3.1` in order to retrieve some typing fixes Related PR: cozy/cozy-client#1553 Related PR: cozy/cozy-client#1556
`cozy-pouch-link` has been upgraded to `50.3.1` in order to retrieve `startReplicationWithDebounce()` method implementation `cozy-client` has been upgraded to `50.3.1` in order to retrieve some typing fixes Related PR: cozy/cozy-client#1553 Related PR: cozy/cozy-client#1556
We want to be able to debounce calls to
startReplication()
This commit adds the
startReplicationWithDebounce()
method that is responsible to debounce the call ofstartReplication()
by a specific delayThe debounce delay can be configured using the CozyPouchLink constructor's
syncDebounceDelayInMs
optionCalling the
startReplication()
will cancel debounced calls and immediately execute the replicationRelated PRs: