Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Ref #450, create resolved bookmarks from the oldest to newest by sync…
Browse files Browse the repository at this point in the history
…Timestamp.
  • Loading branch information
iccub authored and Joel Reis committed Jan 16, 2019
1 parent 191dbff commit eb28250
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 {
// Bookmarks 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 eb28250

Please sign in to comment.