Review a bit about duplicates handling
- Read profile(withId:) without fetcher - Refine redundant log about duplicated profiles
This commit is contained in:
parent
c0f105fedb
commit
5cafd9794d
|
@ -335,8 +335,11 @@ extension ProfileManager {
|
|||
allNames.remove(at: i)
|
||||
}
|
||||
let duplicates = Set(allNames)
|
||||
|
||||
pp_log.debug("Duplicate profile names: \(duplicates)")
|
||||
guard !duplicates.isEmpty else {
|
||||
pp_log.debug("No duplicated profiles")
|
||||
return
|
||||
}
|
||||
pp_log.debug("Duplicated profile names: \(duplicates)")
|
||||
|
||||
var renamedProfiles: [Profile] = []
|
||||
duplicates.forEach { name in
|
||||
|
|
|
@ -35,7 +35,7 @@ extension ProfileManager {
|
|||
|
||||
public init(persistence: Persistence) {
|
||||
profileRepository = ProfileRepository(persistence.context)
|
||||
fetchedHeaders = profileRepository.headers()
|
||||
fetchedHeaders = profileRepository.fetchedHeaders()
|
||||
}
|
||||
|
||||
public var allHeaders: [UUID: Profile.Header] {
|
||||
|
@ -43,7 +43,7 @@ extension ProfileManager {
|
|||
}
|
||||
|
||||
public func profile(withId id: UUID) -> Profile? {
|
||||
profileRepository.profile(withId: id).value
|
||||
profileRepository.profile(withId: id)
|
||||
}
|
||||
|
||||
public func saveProfiles(_ profiles: [Profile]) {
|
||||
|
|
|
@ -34,7 +34,7 @@ class ProfileRepository: Repository {
|
|||
self.context = context
|
||||
}
|
||||
|
||||
func headers() -> FetchedValueHolder<[UUID: Profile.Header]> {
|
||||
func fetchedHeaders() -> FetchedValueHolder<[UUID: Profile.Header]> {
|
||||
let request: NSFetchRequest<NSFetchRequestResult> = CDProfile.fetchRequest()
|
||||
request.sortDescriptors = [
|
||||
.init(keyPath: \CDProfile.uuid, ascending: true),
|
||||
|
@ -63,8 +63,8 @@ class ProfileRepository: Repository {
|
|||
)
|
||||
}
|
||||
|
||||
func profile(withId id: UUID) -> FetchedValueHolder<Profile?> {
|
||||
let request: NSFetchRequest<NSFetchRequestResult> = CDProfile.fetchRequest()
|
||||
func profile(withId id: UUID) -> Profile? {
|
||||
let request = CDProfile.fetchRequest()
|
||||
request.sortDescriptors = [
|
||||
.init(keyPath: \CDProfile.lastUpdate, ascending: false)
|
||||
]
|
||||
|
@ -72,22 +72,16 @@ class ProfileRepository: Repository {
|
|||
format: "uuid == %@",
|
||||
id.uuidString
|
||||
)
|
||||
return .init(
|
||||
context: context,
|
||||
request: request,
|
||||
mapping: {
|
||||
guard let dto = $0.first as? CDProfile else {
|
||||
return nil
|
||||
}
|
||||
do {
|
||||
return try ProfileMapper.toModel(dto)
|
||||
} catch {
|
||||
pp_log.error("Unable to map CDProfile: \(error)")
|
||||
let results = try context.fetch(request)
|
||||
guard let recent = results.first else {
|
||||
return nil
|
||||
}
|
||||
return try ProfileMapper.toModel(recent)
|
||||
} catch {
|
||||
pp_log.error("Unable to fetch profile: \(error)")
|
||||
return nil
|
||||
}
|
||||
},
|
||||
initial: nil
|
||||
)
|
||||
}
|
||||
|
||||
func saveProfiles(_ profiles: [Profile]) throws {
|
||||
|
|
Loading…
Reference in New Issue