Skip to content

Commit

Permalink
Fix brave#450, create resolved bookmarks from the oldest to newest by…
Browse files Browse the repository at this point in the history
… syncTimestamp.
  • Loading branch information
iccub committed Jan 14, 2019
1 parent 2a49f27 commit eb1b919
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Data/sync/Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,20 @@ extension Sync {
guard var fetchedRecords = recordType.fetchedModelType?.syncRecords(recordJSON) else { return }

// Currently only prefs are device related
if recordType == .prefs, let data = fetchedRecords as? [SyncDevice] {
if recordType == .prefs {
// Devices have really bad data filtering, so need to manually process more of it
// Sort to not rely on API - Reverse sort, so unique pulls the `latest` not just the `first`
fetchedRecords = data.sorted { device1, device2 in
fetchedRecords = fetchedRecords.sorted { device1, device2 in
device1.syncTimestamp ?? -1 > device2.syncTimestamp ?? -1 }.unique { $0.objectId ?? [] == $1.objectId ?? [] }

} else if recordType == .bookmark {
// Bookmars are sorted to have the oldest bookmark to come in first, so it can be added before it's children.
fetchedRecords = fetchedRecords.sorted(by: {
let firstTimestamp = $0.syncTimestamp ?? 0
let secondTimestamp = $1.syncTimestamp ?? 0

return firstTimestamp < secondTimestamp
})
}

let context = DataController.newBackgroundContext()
Expand Down

0 comments on commit eb1b919

Please sign in to comment.