I have a dating application iOS and Android that's retrieving keys slow up-to 10 seconds. I've followed all the recommendations on firebase real-time documentation but as I'm getting more users it's affecting the performance of my application. I've included ".indexOn": ["g"] and doing my filtering once I receive the keys by putting the information I need onto the key so I don't have to do a second query since geofire doesn't support querying. While geofire observing keys the app is practically unusable until it completes its read. I'm very fond of firebase but should I be considering migrating to another service for scalability and efficiency?
DispatchQueue.global(qos: .background).async {
let result = userDistance * 1609.344
let center = CLLocation(latitude: userlat, longitude: userlon)
let searchRegion = MKCoordinateRegion(center: center.coordinate, latitudinalMeters: result, longitudinalMeters: result)
let geofireRef = Database.database().reference().child("location")
let geoFire = GeoFire(firebaseRef: geofireRef)
print("\(startingPoint.timeIntervalSinceNow * -1) Started Here")
geoFire.query(with: searchRegion).observe(.keyEntered) { (key: String!, location: CLLocation!) in
print("key entered")
}
geoFire.query(with: searchRegion).observeReady {
print("\(startingPoint.timeIntervalSinceNow * -1) Finished Here")
}
}
Structure
--> location
---> key
----> g: <geohash>
-----> l:
-------> 0: Lat
-------> 1: Lon
Index:
"location": {
".read": "auth !== null",
".write": "auth !== null",
".indexOn": ["g"]
}
Query Test:
ref.child("location").queryOrdered(byChild: "g").queryLimited(toFirst: 20000).observeSingleEvent(of: .value) { (snapshot) in
print("\(timeit.timeIntervalSinceNow * -1) Finished Here")
}