benwinding / react-admin-firebase

A firebase data provider for the react-admin framework
https://benwinding.github.io/react-admin-firebase/
MIT License
460 stars 175 forks source link

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

Closed thuan1412 closed 2 months ago

thuan1412 commented 4 years ago

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 commented 4 years ago

` 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?

simokhalil commented 3 years ago

Any updates about this ? Experiencing the same problem here

thuan1412 commented 3 years ago

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

simokhalil commented 3 years ago

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

MMostafaKamal commented 3 years ago

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.