Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase Firestore-更新缓慢?_Firebase_React Native_Google Cloud Firestore_React Native Firebase - Fatal编程技术网

Firebase Firestore-更新缓慢?

Firebase Firestore-更新缓慢?,firebase,react-native,google-cloud-firestore,react-native-firebase,Firebase,React Native,Google Cloud Firestore,React Native Firebase,乐观更新在Firestore中的运行速度似乎不如预期的快。我看到的更新时间至少为200毫秒,介于写入Firestore和触发快照侦听器之间。我使用的是react原生firebase库,但我认为问题不太可能起源于此。该库只是本机SDK的一个薄包装层。我已经启用了离线持久性,但无论是否连接互联网,其行为都是一样的 以下代码片段说明了该问题: class App extends React.Component{ componentDidMount(){ db.collection("cit

乐观更新在Firestore中的运行速度似乎不如预期的快。我看到的更新时间至少为200毫秒,介于写入Firestore和触发快照侦听器之间。我使用的是react原生firebase库,但我认为问题不太可能起源于此。该库只是本机SDK的一个薄包装层。我已经启用了离线持久性,但无论是否连接互联网,其行为都是一样的

以下代码片段说明了该问题:

class App extends React.Component{
  componentDidMount(){
    db.collection("cities").onSnapshot(function(qsnap) {
          this.setState({cities: qsnap.docs.map(s => s.data())})
      });
  }

  addCity(){
    db.collection("cities").add({
      name: Math.random(),
      country: "Japan"
    })
  }

 render(){

  //After clicking add city, the new render doesn't happen until
  //after a minimum time of 200 ms :(

  <View>
    <TouchableOpacity onPress={this.addCity}>Add city</TouchableOpacity>
    {this.state.cities.map(c => <Text>{c.name}</Text>)}
  </View>
  }
}
类应用程序扩展了React.Component{
componentDidMount(){
数据库集合(“城市”).onSnapshot(功能(qsnap){
this.setState({cities:qsnap.docs.map(s=>s.data())})
});
}
addCity(){
db.集合(“城市”)。添加({
名称:Math.random(),
国家:“日本”
})
}
render(){
//单击“添加城市”后,直到
//至少200毫秒后:(
添加城市
{this.state.cities.map(c=>{c.name}}
}
}

有什么我做错了或可以做得不一样的吗?我喜欢订阅数据存储中的快照并直接从中呈现UI,然后直接写入数据存储并通过乐观传播立即更新UI的模式。

您是否有代码可以共享,其行为与您可能体验到的不同t?更新了代码示例嘿,你有关于这个问题的任何消息吗,我在这里也面临同样的问题。谢谢相似的问题:到目前为止,我的结论是对延迟补偿时间几乎没有保证,但文档大小可能确实有影响。