Fix inverted profile lastUpdate logic
- Least recent was set last in the headers dictionary, thus overwriting most recent (ascending = false) - Mapping full profiles directly to array was generating duplicates, use a dictionary to keep ID unicity
This commit is contained in:
parent
0464cd0476
commit
1c64253a1f
|
@ -39,7 +39,7 @@ class ProfileRepository: Repository {
|
|||
let request: NSFetchRequest<NSFetchRequestResult> = CDProfile.fetchRequest()
|
||||
request.sortDescriptors = [
|
||||
.init(keyPath: \CDProfile.uuid, ascending: true),
|
||||
.init(keyPath: \CDProfile.lastUpdate, ascending: false)
|
||||
.init(keyPath: \CDProfile.lastUpdate, ascending: true)
|
||||
]
|
||||
request.propertiesToFetch = [
|
||||
"uuid",
|
||||
|
@ -69,11 +69,17 @@ class ProfileRepository: Repository {
|
|||
let request = CDProfile.fetchRequest()
|
||||
request.sortDescriptors = [
|
||||
.init(keyPath: \CDProfile.uuid, ascending: true),
|
||||
.init(keyPath: \CDProfile.lastUpdate, ascending: false)
|
||||
.init(keyPath: \CDProfile.lastUpdate, ascending: true)
|
||||
]
|
||||
do {
|
||||
let results = try context.fetch(request)
|
||||
return try results.compactMap(ProfileMapper.toModel)
|
||||
let map = try results.reduce(into: [UUID: Profile]()) {
|
||||
guard let profile = try ProfileMapper.toModel($1) else {
|
||||
return
|
||||
}
|
||||
$0[profile.id] = profile
|
||||
}
|
||||
return Array(map.values)
|
||||
} catch {
|
||||
pp_log.error("Unable to fetch profiles: \(error)")
|
||||
return []
|
||||
|
|
Loading…
Reference in New Issue