Geofire 在检索密钥时非常慢/不能很好地扩展

问题描述

我有一个 iOS 和 Android 约会应用程序,它检索密钥的速度慢达 10 秒。我遵循了有关 firebase 实时文档的所有建议,但随着用户越来越多,它影响了我的应用程序的性能。我已经包含了 ".indexOn": ["g"] 并在收到密钥后通过将我需要的信息放在密钥上来进行过滤,因此我不必进行第二次查询,因为 geofire 不支持查询.虽然 geofire 观察键,但在完成读取之前,该应用程序实际上无法使用。我非常喜欢 firebase,但我是否应该考虑迁移到其他服务以提高可扩展性和效率?

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")

    }
}

结构

--> location
---> key
----> g: <geohash>
-----> l: 
-------> 0: Lat
-------> 1: Lon

索引:

  "location": {
    ".read": "auth !== null",".write": "auth !== null",".indexOn": ["g"]
    }

查询测试:

ref.child("location").queryOrdered(byChild: "g").queryLimited(toFirst: 20000).observeSingleEvent(of: .value) { (snapshot) in
    print("\(timeit.timeIntervalSinceNow * -1) Finished Here")
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)