Skip to content

Commit

Permalink
Reset bookmarks sync timestamp after migrating to FFS favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Oct 13, 2023
1 parent d0d1145 commit c060d1e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DuckDuckGo/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
let environment = defaultEnvironment
#endif
let syncDataProviders = SyncDataProviders(bookmarksDatabase: BookmarkDatabase.shared.db)
if bookmarksManager.didMigrateToFormFactorSpecificFavorites {
syncDataProviders.bookmarksAdapter.shouldResetBookmarksSyncTimestamp = true
}
let syncService = DDGSync(dataProvidersSource: syncDataProviders, errorEvents: SyncErrorHandler(), log: OSLog.sync, environment: environment)
syncService.initializeIfNeeded()
syncDataProviders.setUpDatabaseCleaners(syncService: syncService)
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Bookmarks/Model/BookmarkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protocol BookmarkManager: AnyObject {
func importBookmarks(_ bookmarks: ImportedBookmarks, source: BookmarkImportSource) -> BookmarkImportResult

func handleFavoritesAfterDisablingSync()
var didMigrateToFormFactorSpecificFavorites: Bool { get }

// Wrapper definition in a protocol is not supported yet
var listPublisher: Published<BookmarkList?>.Publisher { get }
Expand Down Expand Up @@ -81,6 +82,10 @@ final class LocalBookmarkManager: BookmarkManager {
@Published private(set) var list: BookmarkList?
var listPublisher: Published<BookmarkList?>.Publisher { $list }

var didMigrateToFormFactorSpecificFavorites: Bool {
bookmarkStore.didMigrateToFormFactorSpecificFavorites
}

private lazy var bookmarkStore: BookmarkStore = LocalBookmarkStore(bookmarkDatabase: BookmarkDatabase.shared)
private lazy var faviconManagement: FaviconManagement = FaviconManager.shared

Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Bookmarks/Services/BookmarkStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ protocol BookmarkStore {
func importBookmarks(_ bookmarks: ImportedBookmarks, source: BookmarkImportSource) -> BookmarkImportResult

func handleFavoritesAfterDisablingSync()
var didMigrateToFormFactorSpecificFavorites: Bool { get }
}
2 changes: 2 additions & 0 deletions DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class LocalBookmarkStore: BookmarkStore {
}

private(set) var favoritesDisplayMode: FavoritesDisplayMode
private(set) var didMigrateToFormFactorSpecificFavorites: Bool = false

private let contextProvider: () -> NSManagedObjectContext

Expand Down Expand Up @@ -214,6 +215,7 @@ final class LocalBookmarkStore: BookmarkStore {

if context.hasChanges {
try context.save(onErrorFire: .bookmarksMigrationCouldNotPrepareMultipleFavoriteFolders)
didMigrateToFormFactorSpecificFavorites = true
}
} catch {
Thread.sleep(forTimeInterval: 1)
Expand Down
8 changes: 8 additions & 0 deletions DuckDuckGo/Sync/SyncBookmarksAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ final class SyncBookmarksAdapter {

private(set) var provider: BookmarksProvider?
let databaseCleaner: BookmarkDatabaseCleaner
var shouldResetBookmarksSyncTimestamp: Bool = false {
willSet {
assert(provider == nil, "Setting this value has no effect after provider has been instantiated")
}
}

init(
database: CoreDataDatabase,
Expand Down Expand Up @@ -63,6 +68,9 @@ final class SyncBookmarksAdapter {
metadataStore: metadataStore,
syncDidUpdateData: LocalBookmarkManager.shared.loadBookmarks
)
if shouldResetBookmarksSyncTimestamp {
provider.lastSyncTimestamp = nil
}

syncErrorCancellable = provider.syncErrorPublisher
.sink { error in
Expand Down
1 change: 1 addition & 0 deletions UnitTests/Bookmarks/Services/BookmarkStoreMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@ final class BookmarkStoreMock: BookmarkStore {

func applyFavoritesDisplayMode(_ configuration: FavoritesDisplayMode) {}
func handleFavoritesAfterDisablingSync() {}
var didMigrateToFormFactorSpecificFavorites: Bool = false
}
2 changes: 2 additions & 0 deletions UnitTests/HomePage/Mocks/MockBookmarkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class MockBookmarkManager: BookmarkManager {

func handleFavoritesAfterDisablingSync() {}

var didMigrateToFormFactorSpecificFavorites: Bool = false

@Published var list: BookmarkList?

var listPublisher: Published<BookmarkList?>.Publisher { $list }
Expand Down

0 comments on commit c060d1e

Please sign in to comment.