react-admin-firebase icon indicating copy to clipboard operation
react-admin-firebase copied to clipboard

It take too long to get data from a big firebase collection

Open thuan1412 opened this issue 5 years ago • 5 comments

My collection( namely Player) has roughly 17000 document. When i open the list of players( get 10 players from 17000), it take me about 15s to load the page. I have tried fetch the same data using firebase-admin and it take less than 1s to get 10 players. So my question is how can i improve this slow loading.

thuan1412 avatar Jul 23 '20 09:07 thuan1412

` const collectionQuery = filterSafe.collectionQuery; delete filterSafe.collectionQuery;

const r = await this.tryGetResource(
  resourceName,
  "REFRESH",
  collectionQuery
);
const data = r.list;
if (params.sort != null) {
  const { field, order } = params.sort;
  if (order === "ASC") {
    sortArray(data, field, "asc");
  } else {
    sortArray(data, field, "desc");
  }
}
let softDeleted = data;
if (this.options.softDelete && !Object.keys(filterSafe).includes('deleted')) {
  softDeleted = data.filter(doc => !doc['deleted'])
}
const filteredData = filterArray(softDeleted, filterSafe);`

This code from file FirebaseClient.ts . Will this code will get all data from the firebase collection then sort and filter it? If right, why don't you use firebase sort, filter API for this? I think this is the reason make the program slow when working with large firebase collection?

thuan1412 avatar Jul 23 '20 16:07 thuan1412

Any updates about this ? Experiencing the same problem here

simokhalil avatar Oct 28 '20 08:10 simokhalil

@simokhalil You have to create a new FirebaseProvider that use Firebase to sort, find, v.v document.

thuan1412 avatar Oct 29 '20 16:10 thuan1412

Found this interesting PR #125 that implements a data provider using the Firebase SDK instead of downloading all data, and it's working great so far, except the pagination but that's not a problem for me

simokhalil avatar Oct 29 '20 18:10 simokhalil

Does the library implement backend pagination ? because I understand that it's not possible to get a collection count in Firestore without performing a read on all documents.

MMostafaKamal avatar Dec 29 '20 09:12 MMostafaKamal