0
我使用firebase 3.4.1和反應原生0.34.1。firebase與反應原生,太慢
令我驚訝的是,從firebase接收檢索到的數據非常緩慢。
這是我的反應本機測試代碼。
class test1 extends Component {
constructor(){
super();
let config = {
apiKey: "xxxxxxxxxxxxxx",
authDomain: "yyyyyyyy.firebaseapp.com",
databaseURL: "https://zzzzzz.firebaseio.com",
};
Firebase.initializeApp(config);
this.rootRef = Firebase.database().ref();
this.postRef = this.rootRef.child('posts');
this.state = {
like : 'like : ',
comment : 'comment : ',
};
componentWillMount(){
console.debug('componentWillMount');
let num = 0;
let time = new Date().getTime();
this.postRef.orderByKey().limitToLast(10).once('value')
.then((postsnap) => {
console.debug(new Date().getTime() - time);
postsnap.forEach((postItem) => {
console.debug(num++);
console.debug(new Date().getTime() - time);
this.setState({
like : this.state.like + postItem.child('like').numChildren() + ', ',
comment : this.state.comment + postItem.child('comment').numChildren() + ', ',
});
});
});
}
render() {
return (
<View style={styles.container}>
<Text>
{this.state.like}
</Text>
<Text>
{this.state.comment}
</Text>
</View>
);
}
}
我的火力數據庫的結構非常簡單, 'rootref' 僅擁有6 '帖子'。
componentWillMount
8760
0
8761
1
8766
2
8767
3
8768
4
8769
5
8772
你們是否有從火力更快的檢索數據的任何想法?
數據檢索性能通常是您請求的數據量的組合,然後將其除以您可用的帶寬。這可能是因爲您的React Native設置有問題,但我們無法爲此做任何事情。你能設置一個定期的React jsbin/jsfiddle來重現問題嗎? –
它似乎是連接問題,..我想.. 連接後沒有成本時間。 –