首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用firebase实时数据库,我的条目大约有300个条目。现在在数据快照中未收到来自firebase的响应

使用firebase实时数据库,我的条目大约有300个条目。现在在数据快照中未收到来自firebase的响应
EN

Stack Overflow用户
提问于 2019-05-28 13:22:59
回答 1查看 43关注 0票数 0

我在我的安卓应用中使用了Firebase realtime database。我在表中的条目大约是300个。我无法从Datasnapshot中的Firebase获取数据。有时它在加载20分钟后就能正常工作。如何快速访问我的数据和响应?对于相同的数据库和相同的查询,它在iOS中运行得很好,速度非常快。

代码语言:javascript
运行
复制
private void checkBookingInfo() throws Exception {

    mDatabaseReference.child(FireBaseConstants.BOOKING_INFO_TABLE).limitToFirst(10).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {


            if (dataSnapshot != null) {
                countArrival = 0;
                countDeparture = 0;

                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    //check  arrivals date matches with today's date then increment counter
                    if (snapshot.hasChild(FireBaseConstants.ARRIVAL_DATE)) {
                        String currentDate = Utils.getCurrentDate();
                        String arrivalDate = snapshot.child(FireBaseConstants.ARRIVAL_DATE).getValue().toString();
                        String status = snapshot.child(FireBaseConstants.STATUS).getValue().toString();

                        if (currentDate.equalsIgnoreCase(arrivalDate) && !status.equalsIgnoreCase("Cancel")) {
                            countArrival++;
                        }
                    }
                    //check  departure date matches with today's date then increment counter
                    if (snapshot.hasChild(FireBaseConstants.DEPARTURE_DATE)) {
                        String currentDate = Utils.getCurrentDate();
                        String departureDate = snapshot.child(FireBaseConstants.DEPARTURE_DATE).getValue().toString();
                        String status = snapshot.child(FireBaseConstants.STATUS).getValue().toString();
                        if (currentDate.equalsIgnoreCase(departureDate) && !status.equalsIgnoreCase("Cancel")) {
                            countDeparture++;
                        }
                    }
                }
                setValueInEditText();
            } else {

            }

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e("notme", "");
        }
    });
}
EN

回答 1

Stack Overflow用户

发布于 2019-05-28 13:31:01

若要提高Firebase查询的性能,可以在排序查询所依据的字段上添加索引。喜欢

代码语言:javascript
运行
复制
  {
   "rules": {
      "YOUR_NODE": {
         ".indexOn": ["FIELD1", "FIELD2"]
     }
   }
  }

您可以找到帮助链接here

Firebase还说here

要点:每次在指定的数据库引用处更改数据时都会调用onDataChange()方法,包括对子项的更改。要限制快照的大小,请仅在查看更改所需的最高级别进行连接。例如,不建议将侦听器附加到数据库的根目录。

但是,即使没有应用索引,仍然需要20分钟的时间,你需要检查你的源代码,在UI中可能有一些其他问题,可能是数据即将到来,但没有填充到UI中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56335472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档