Skip to content
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

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Nov 4, 2024

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

Related PRs:

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'
Copy link
Contributor

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?

Copy link
Member Author

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()
Copy link
Contributor

@paultranvan paultranvan Nov 5, 2024

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

Copy link
Member Author

@Ldoppea Ldoppea Nov 5, 2024

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
Ldoppea added a commit to cozy/cozy-web-data-proxy that referenced this pull request Nov 5, 2024
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
@Ldoppea Ldoppea merged commit 9089ffc into master Nov 6, 2024
4 checks passed
@Ldoppea Ldoppea deleted the feat/pouch_replication_debounce branch November 6, 2024 09:17
Ldoppea added a commit to cozy/cozy-libs that referenced this pull request Nov 6, 2024
`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
Ldoppea added a commit to cozy/cozy-libs that referenced this pull request Nov 6, 2024
`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
Ldoppea added a commit to cozy/cozy-libs that referenced this pull request Nov 6, 2024
`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
Ldoppea added a commit to cozy/cozy-web-data-proxy that referenced this pull request Nov 6, 2024
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
Ldoppea added a commit to cozy/cozy-web-data-proxy that referenced this pull request Nov 6, 2024
`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
Ldoppea added a commit to cozy/cozy-web-data-proxy that referenced this pull request Nov 6, 2024
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
Ldoppea added a commit to cozy/cozy-web-data-proxy that referenced this pull request Nov 6, 2024
`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
Ldoppea added a commit to cozy/cozy-web-data-proxy that referenced this pull request Nov 6, 2024
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
Ldoppea added a commit to cozy/cozy-web-data-proxy that referenced this pull request Nov 6, 2024
`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
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Nov 26, 2024
`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
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.

3 participants