Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Mage/CoreData/Observation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ enum ObservationState: Int, CustomStringConvertible {

@objc public var primaryObservationForm: [AnyHashable : Any]? {
get {
if let properties = self.properties, let forms = properties[ObservationKey.forms.key] as? [[AnyHashable:Any]] {
if let properties = self.properties, let forms = properties[ObservationKey.forms.key] as? [[AnyHashable:Any]] { // FIXME: This is really slow on self.properties (Transformable) why? what is it? What is it doing? (Profile + test by commenting out and always return nil)
for (index, form) in forms.enumerated() {
// here we can ignore forms which will be deleted
if !self.formsToBeDeleted.contains(index) {
Expand Down
2 changes: 1 addition & 1 deletion Mage/Model/Observation/ObservationMapItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct ObservationMapItem: Equatable, Hashable {
}

extension ObservationMapItem {
init(observation: ObservationLocation) {
init(observation: ObservationLocation) { //}, forms: [FormModel]) {
self.observationId = observation.observation?.objectID.uriRepresentation()
self.observationLocationId = observation.objectID.uriRepresentation()
self.formId = Int(observation.formId)
Expand Down
6 changes: 4 additions & 2 deletions Mage/ObservationShapeStyleParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
@objc static func style(
observation: Observation,
primaryFieldText: String? = nil,
secondaryFieldText: String? = nil
secondaryFieldText: String? = nil,
// forms: [Forms]
) -> ObservationShapeStyle {
let style = ObservationShapeStyle()

var form: FormModel?
if let primaryObservationForm = observation.primaryObservationForm,
let formId = primaryObservationForm[EventKey.formId.key] as? NSNumber
{
form = ObservationShapeStyleParser.formRepository.getForm(formId: formId)
// FIXME: We need to inject the form, this is very slow to refetch, we should cache all forms needed several levels up from this call
form = ObservationShapeStyleParser.formRepository.getForm(formId: formId) // FIXME: Comment out to see perf improvement (and skipping styling)
}

// let form = observation.primaryEventForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,51 +204,6 @@ class ObservationLocationCoreDataDataSource: CoreDataDataSource<ObservationLocat
}
}

func getMapItems(
observationUri: URL?,
minLatitude: Double?,
maxLatitude: Double?,
minLongitude: Double?,
maxLongitude: Double?
) async -> [ObservationMapItem] {
guard let observationUri = observationUri else {
return []
}
guard let context = context else { return [] }
return await context.perform {

var predicates: [NSPredicate] = []
if let minLatitude = minLatitude,
let maxLatitude = maxLatitude,
let minLongitude = minLongitude,
let maxLongitude = maxLongitude
{
predicates.append(NSPredicate(
format: "maxLatitude >= %lf AND minLatitude <= %lf AND maxLongitude >= %lf AND minLongitude <= %lf",
minLatitude,
maxLatitude,
minLongitude,
maxLongitude
))
}

let predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)
let fetchRequest = ObservationLocation.fetchRequest()
fetchRequest.predicate = predicate

let results = context.fetch(request: fetchRequest)

return results?.sorted(by: { one, two in
one.order < two.order
}).filter({ location in
location.observation?.objectID.uriRepresentation() == observationUri
})
.map({ location in
ObservationMapItem(observation: location)
}) ?? []
}
}

func getMapItems(
minLatitude: Double?,
maxLatitude: Double?,
Expand Down Expand Up @@ -277,7 +232,7 @@ class ObservationLocationCoreDataDataSource: CoreDataDataSource<ObservationLocat

let results = context.fetch(request: fetchRequest)
return results?.compactMap { location in
return ObservationMapItem(observation: location)
return ObservationMapItem(observation: location) // FIXME: SLOW because of getForm. cache and pass in.
} ?? []
}
}
Expand Down