【问题标题】:Why does the first firebase call for real time database take too much time after first response it works much faster为什么第一次响应后实时数据库的第一次firebase调用需要太多时间它的工作速度要快得多
【发布时间】:2018-04-07 22:01:23
【问题描述】:

我在我的应用程序中使用 firebase 实时数据库,但我遇到了一个奇怪的问题。在第一次响应后,第一次 firebase 调用花费了太多时间。

 Database.database().reference().child(FireBaseTable.bpmTable).child(firebaseKey).queryOrdered(byChild: "timestamp").observeSingleEvent(of: .value, with: { (snapshot) in
                print("Initial load done2")
            })

第一次响应后,具有差异/相同键的相同代码提供更快的响应。

【问题讨论】:

    标签: xcode firebase swift3 firebase-realtime-database ios11


    【解决方案1】:

    一种解决方案可能是在您的规则中索引数据:https://firebase.google.com/docs/database/security/indexing-data

    {
      "lambeosaurus": {
        "height" : 2.1,
        "length" : 12.5,
        "weight": 5000
      },
      "stegosaurus": {
        "height" : 4,
        "length" : 9,
        "weight" : 2500
      }
    }
    

    索引可以这样设置:

    {
      "rules": {
        "dinosaurs": {
          ".indexOn": ["height", "length"]
        }
      }
    }
    

    “Firebase 允许您使用 任意子键。如果你提前知道你的索引是什么, 您可以通过 Firebase Realtime 中的 .indexOn 规则定义它们 提高查询性能的数据库规则。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多