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: Trigger replication on appstate changes and realtime events #1278

Merged

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Jan 13, 2025

With previous PouchDB/offline implementation, the app was able to trigger a full replication on application's startup, but then nothing would be replicating until next app's restart

This PR is responsible to implement 2 new scenario:

  • When the app goes to background and then come back to foreground, then we trigger a replication
  • When the app receives a realtime event from one of the CozyPouchLink's configured doctypes, then we trigger a replication

For both scenario, the replication is debounced for 30s with a maximum of 10min

@Ldoppea Ldoppea changed the base branch from master to feat/remove_old_storage January 13, 2025 18:08
@Ldoppea Ldoppea changed the title Feat/trigger replication on appstate and realtime feat: Trigger replication on appstate changes and realtime events Jan 13, 2025
@Ldoppea Ldoppea marked this pull request as ready for review January 16, 2025 10:37
@Ldoppea Ldoppea force-pushed the feat/remove_old_storage branch from b2a3b4e to b87dafb Compare January 16, 2025 10:39
@Ldoppea Ldoppea force-pushed the feat/trigger_replication_on_appstate_and_realtime branch 2 times, most recently from f50d62d to 11582fc Compare January 16, 2025 10:54
Copy link
Contributor

@paultranvan paultranvan left a comment

Choose a reason for hiding this comment

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

Looks good 👍

offlineDoctypes.forEach(doctype => {
realtime.subscribe('created', doctype, triggerReplicationCreated)
realtime.subscribe('updated', doctype, triggerReplicationUpdated)
realtime.subscribe('deleted', doctype, triggerReplicationDeleted)
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize we trigger a full replication on all doctypes for any realtime change, while we probably should only replicate for the concerned doctype, to save resources. But this is an improvement that can be made for later

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we will have to implement something to handle that scenario. For now the replication method always replicate all pouches and no mechanism has been implemented to debounce replications separately.

@Ldoppea Ldoppea force-pushed the feat/remove_old_storage branch from b87dafb to 813e264 Compare January 17, 2025 11:22
Base automatically changed from feat/remove_old_storage to feat/meta_offline January 17, 2025 11:31
@Ldoppea Ldoppea force-pushed the feat/trigger_replication_on_appstate_and_realtime branch from 11582fc to 77c1030 Compare January 17, 2025 11:33
@Ldoppea Ldoppea merged commit 1f0982c into feat/meta_offline Jan 17, 2025
1 check passed
@Ldoppea Ldoppea deleted the feat/trigger_replication_on_appstate_and_realtime branch January 17, 2025 11:44
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