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来重现问题吗? –
它似乎是连接问题,..我想.. 连接后没有成本时间。 –