2016-09-30 3 views
0

난 파이어베이스 3.4.1을 사용하고 반응 네이티브 0.34.1.반응이 너무 느린 네이티브 화염대

검색된 데이터를 수신하는 것이 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 

너희들 중포 기지에서 빠른 데이터 검색에 대한 어떤 생각을 가지고 있습니까?

+0

데이터 검색 성능은 일반적으로 요청한 데이터의 양을 조합 한 다음 사용 가능한 대역폭으로 나누는 것입니다. React Native 설정에 문제가있을 수 있지만 그 일을 위해 할 수있는 방법은 없습니다. 문제를 재현하는 정규 jsbin/jsfiddle을 설정할 수 있습니까? –

+0

연결 문제 인 것 같아요. 접속 후 시간이 없습니다. –

답변

0

Reference을 얻는 데 싱글 톤 패턴을 사용하는 것이 훨씬 좋습니다. 매번 Firebase.initializeApp을 호출하는 대신 별도의 모듈에 넣음으로써 글로벌하게 만듭니다. 그런 다음 인스턴스화 된 참조를 Firebase.database().ref()으로 내 보냅니다. 앱 전체에서 사용하십시오.

어쨌든, 나는이 방법을 사용해도 1 노드 쿼리 (node/key)에 대해 얻은 최소로드 시간이 ~ 200 밀리 초이며 실제로 느리다는 것을 발견했습니다.

관련 문제