Firebase Android offline performance

后端 未结 2 737
北恋
北恋 2021-01-05 04:43

When storing approximately 5000 sub nodes under a single node, initialising firebase becomes very slow when making use of the offline capabilities. It takes ~30 seconds befo

2条回答
  •  误落风尘
    2021-01-05 05:42

    So sharding the data so one root node contains at most 200 sub nodes seems to be the answer for now. I'm setting .keepSynced(true) on the shards and this results in much better performance.

    In order to present the sharded list in a single recycler view, I created a class FirebaseArrays which is a collection of FirebaseArray that aggregates multiple arrays into a single observable collection.
    https://gist.github.com/ndefeijter/2191f8a43ce903c5d9ea69f02c7ee7e9

    I also adapted the FirebaseRecyclerAdapter to use a FirebaseArrays as underlying data structure instead of a single FirebaseArray. The interface is extended using some methods to add additional Firebase paths (i.e. shards).
    https://gist.github.com/ndefeijter/d98eb5f643b5faf5476b8a611de912c1

    These paths are added upon a 'load more' event (e.g. in case endless scrolling).

    private void loadMore() {
    
        final View view = getView();
        if (null != view) {
            final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
            final FirebaseRecyclerAdapter2 adapter = (FirebaseRecyclerAdapter2) recyclerView.getAdapter();
            adapter.addQuery(nextQuery());
        }
    }
    

提交回复
热议问题