Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Add support for per-model Sync Data Providers initialization #433

Merged
merged 8 commits into from
Jul 26, 2023

Conversation

ayoy
Copy link
Contributor

@ayoy ayoy commented Jul 25, 2023

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/0/1205093266805582/f
iOS PR: duckduckgo/iOS#1863
macOS PR: duckduckgo/macos-browser#1387
What kind of version bump will this require?: Major

Description:
Rework Sync initialization mechanism by moving sync data models initialization from
DDGSync (where it was tied to account signup/login flow) to data models themselves.
Sync Metadata is leveraged to store sync setup state per data model. Two values are
possible: needs remote data fetch (a.k.a initial sync) or ready to sync.
Decoupling account flow from data models initialization allows to initialize data models
independently of user turning on sync, which is a requirement to support initial sync
for new syncable models added with client app updates.
Also DataProvider class has been added – it's a dedicated sync data providers superclass
that also encapsulates common logic, making individual data providers simpler.

Steps to test this PR:
iOS:

  1. Start off with a fresh app from App Store. Enable sync and create a few bookmarks.
  2. Enter airplane mode.
  3. Add new bookmark.
  4. Kill the app. Disable airplane mode.
  5. Run the app from Xcode.
  6. Observe logs and make sure that PATCH request has been sent (and not GET, which would mean that initial sync
    was triggered for an active account).

macOS:

  1. Start off with a fresh app from Xcode. Add a bookmark.
  2. Enable Sync logging.
  3. Join iOS sync account and make sure GET request was sent before a PATCH request.
  4. Disable sync and re-enable sync (new sync account). Make sure that PATCH request was sent.
  5. Disable sync and re-join iOS account. Make sure that GET request was sent before a PATCH request.

OS Testing:

  • iOS 14
  • iOS 15
  • iOS 16
  • macOS 10.15
  • macOS 11
  • macOS 12

Internal references:

Software Engineering Expectations
Technical Design Template

@ayoy ayoy self-assigned this Jul 25, 2023
@ayoy ayoy requested a review from bwaresiak July 25, 2023 11:15
@ayoy ayoy marked this pull request as ready for review July 25, 2023 11:16
@ayoy ayoy assigned bwaresiak and unassigned ayoy Jul 25, 2023
Copy link
Collaborator

@bwaresiak bwaresiak left a comment

Choose a reason for hiding this comment

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

LGTM, two small comments inline.

@@ -230,6 +230,7 @@ public class DDGSync: DDGSyncing {
dependencies.scheduler.isEnabled = false
startSyncCancellable?.cancel()
syncQueueCancellable?.cancel()
try syncQueue?.dataProviders.forEach { try $0.deregisterFeature() }
syncQueue = nil
authState = .inactive
try dependencies.secureStore.removeAccount()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should handle any of these try calls somehow... pixel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me add a task for it. I'm sure it's not the only place we need to handle.

open class DataProvider: DataProviding {

public let feature: Feature
public let metadataStore: SyncMetadataStore
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be public, or rather encapsulated? I don't think we want anyone to use it directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course we don't want to expose it 👍 thanks!

@ayoy ayoy assigned ayoy and unassigned bwaresiak Jul 26, 2023
@ayoy ayoy merged commit 188ba0c into main Jul 26, 2023
@ayoy ayoy deleted the dominik/first-sync-for-new-models branch July 26, 2023 09:43
samsymons added a commit that referenced this pull request Jul 27, 2023
* main:
  Fire Window (#420)
  disable trailing_comma (#434)
  Add support for per-model Sync Data Providers initialization (#433)
afterxleep pushed a commit that referenced this pull request Aug 2, 2023
Task/Issue URL: https://app.asana.com/0/0/1205093266805582/f

Rework Sync initialization mechanism by moving sync data models initialization from
DDGSync (where it was tied to account signup/login flow) to data models themselves.
Sync Metadata is leveraged to store sync setup state per data model. Two values are
possible: needs remote data fetch (a.k.a initial sync) or ready to sync.
Decoupling account flow from data models initialization allows to initialize data models
independently of user turning on sync, which is a requirement to support initial sync
for new syncable models added with client app updates.
Also DataProvider class has been added – it's a dedicated sync data providers superclass
that also encapsulates common logic, making individual data providers simpler.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants