What is the most efficient way to get the overall max speed over all Customers/Cars.
// 157087 Entries (already filtered)
class Customer: Object {
//...
let cars = LinkingObjects(fromType: Car.self, property: "customer")
}
// 2537950 Entries for the 157087 filtered Customers
class Car: Object {
//...
@objc dynamic var customer: Customer?
}
// results here are already filtered (For simplicity i kept the additional filters away)
var results : Results<Customer> = realm.filter("age > 18")
// takes several seconds
let maxSpeed = results.map { $0.cars.max(ofProperty: "speed") as Double? }.max() ?? 0
is there a better way to do so? Just for benchmarking I tried the other way around. It takes just as long
// need to add a `IN` clause because of the pre filtered results (see above)
let cars : Results<Car> = realm.objects(Car.self).filter("customer IN %@", results)
let maxSpeed = cars.max(ofProperty: "speed") as Double?