Skip to content

Commit

Permalink
Improve handling lists in Sync (#2192)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1205884549503153/f

Description:
Improve handling of lists in syncable models' payloads (which currently is limited to bookmarks
folders and favorites folders children). This change updates how lists are sent to Sync in PATCH
payloads by including current state as well as the set of removed and inserted items.
To allow for this, last sync payload is kept for all bookmarks folders in
lastChildrenPayloadReceivedFromSync property added on BookmarkEntity entity.
If the payload is not available (e.g. first sync), the legacy mechanism is used (i.e. sending only
the current contents of the list). The schema of a Sync response payload does not change so
the implementation handles it too.
  • Loading branch information
ayoy authored Dec 5, 2023
1 parent 000aa58 commit fe7db6c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
12 changes: 5 additions & 7 deletions Core/SyncBookmarksAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ public final class SyncBookmarksAdapter {
public let databaseCleaner: BookmarkDatabaseCleaner
public let syncDidCompletePublisher: AnyPublisher<Void, Never>

public var shouldResetBookmarksSyncTimestamp: Bool = false {
willSet {
assert(provider == nil, "Setting this value has no effect after provider has been instantiated")
}
}

@UserDefaultsWrapper(key: .syncBookmarksPaused, defaultValue: false)
static public var isSyncBookmarksPaused: Bool {
didSet {
Expand All @@ -81,6 +75,9 @@ public final class SyncBookmarksAdapter {
@UserDefaultsWrapper(key: .syncBookmarksPausedErrorDisplayed, defaultValue: false)
static private var didShowBookmarksSyncPausedError: Bool

@UserDefaultsWrapper(key: .syncDidMigrateToImprovedListsHandling, defaultValue: false)
private var didMigrateToImprovedListsHandling: Bool

@Published
public var isFaviconsFetchingEnabled: Bool = UserDefaultsWrapper(key: .syncAutomaticallyFetchFavicons, defaultValue: false).wrappedValue {
didSet {
Expand Down Expand Up @@ -149,7 +146,8 @@ public final class SyncBookmarksAdapter {
}
}
)
if shouldResetBookmarksSyncTimestamp {
if !didMigrateToImprovedListsHandling {
didMigrateToImprovedListsHandling = true
provider.lastSyncTimestamp = nil
}

Expand Down
1 change: 1 addition & 0 deletions Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public struct UserDefaultsWrapper<T> {
case syncIsFaviconsFetcherEnabled = "com.duckduckgo.ios.sync-is-favicons-fetcher-enabled"
case syncIsEligibleForFaviconsFetcherOnboarding = "com.duckduckgo.ios.sync-is-eligible-for-favicons-fetcher-onboarding"
case syncDidPresentFaviconsFetcherOnboarding = "com.duckduckgo.ios.sync-did-present-favicons-fetcher-onboarding"
case syncDidMigrateToImprovedListsHandling = "com.duckduckgo.ios.sync-did-migrate-to-improved-lists-handling"

case networkProtectionDebugOptionAlwaysOnDisabled = "com.duckduckgo.network-protection.always-on.disabled"
case networkProtectionWaitlistTermsAndConditionsAccepted = "com.duckduckgo.ios.vpn.terms-and-conditions-accepted"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9217,7 +9217,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 88.0.0;
version = 89.0.0;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/DuckDuckGo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "7b35b4c604f1cf17b48aabf72526b15a2fdcc6ce",
"version": "88.0.0"
"revision": "9a7c2f13f7769221809021371730bde3ab16e575",
"version": "89.0.0"
}
},
{
Expand Down Expand Up @@ -156,7 +156,7 @@
},
{
"package": "TrackerRadarKit",
"repositoryURL": "https://github.com/duckduckgo/TrackerRadarKit",
"repositoryURL": "https://github.com/duckduckgo/TrackerRadarKit.git",
"state": {
"branch": null,
"revision": "4684440d03304e7638a2c8086895367e90987463",
Expand Down
8 changes: 0 additions & 8 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
DatabaseMigration.migrate(to: context)
}

var shouldResetBookmarksSyncTimestamp = false

let preMigrationErrorHandling = EventMapping<BookmarkFormFactorFavoritesMigration.MigrationErrors> { _, error, _, _ in
if let error = error {
Pixel.fire(pixel: .bookmarksCouldNotLoadDatabase,
Expand Down Expand Up @@ -220,11 +218,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
in: context)
if context.hasChanges {
try context.save(onErrorFire: .bookmarksMigrationCouldNotPrepareMultipleFavoriteFolders)
if let syncDataProviders = self?.syncDataProviders {
syncDataProviders.bookmarksAdapter.shouldResetBookmarksSyncTimestamp = true
} else {
shouldResetBookmarksSyncTimestamp = true
}
}
} catch {
Thread.sleep(forTimeInterval: 1)
Expand Down Expand Up @@ -288,7 +281,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
settingHandlers: [FavoritesDisplayModeSyncHandler()],
favoritesDisplayModeStorage: FavoritesDisplayModeStorage()
)
syncDataProviders.bookmarksAdapter.shouldResetBookmarksSyncTimestamp = shouldResetBookmarksSyncTimestamp

let syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: .syncLog, environment: environment)
syncService.initializeIfNeeded()
Expand Down

0 comments on commit fe7db6c

Please sign in to comment.