Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
Firebase: best practice to display items

I would like a suggestion. I'm developing a web app using react-js as frontend and firebase as backend.

For sake of semplicity, say the aim of the web-app is to allow the user to upload some items which are then displayed on the homepage

An item consists of two string: 1) name of item 2) url pointed to an image stored on IPFS

Once the user submit a form, the frontend creates a new doc in a collection in firestore:

await addDoc(collectionRef, newDoc)

Then, in the homepage, I display all the items in the collection

const querySnapshot = await getDocs(collectionRef);
querySnapshot.forEach((doc) => {
    ...
});

This works; however, if I've understood properly, every time the homepage is refreshed the frontend makes N read calls (where N is the number of docs in the collection). Therefore, I'm wondering if its the right approach, is there a better way?

I really appreaciate any suggestion (also regarding potential major safety flaws in this setting)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Every time the homepage is refreshed the frontend makes N read calls (where N is the number of docs in the collection).

With const querySnapshot = await getDocs(collectionRef); this is indeed the case: all the docs in the collection are fetched.

If your collection contains a lot of documents and is fetched frequently this will cost you money and, at one moment, the performance of you app may be degraded (duration of the Firestore query execution and lot of docs transferred from the back-end to the front-end).

One approach to avoid that is to use pagination and fetch only the first X documents and display a link to fetch the X next ones, etc.

There is a page in the Firestore documentation dedicated to pagination implementation.


You could also implement an infinite scroll mechanism instead of a link, to load the next set of X document continuously as the user scrolls down the page. That's just a UI variation and is based on the exact same approach detailed in the Firestore documentation.


Also regarding potential major safety flaws in this setting

Fetching all the docs of a collection or using pagination does not make any difference in terms of security. In any case you should implement security according to your requirements by using security rules (and potentially Firebase Auth as well). And don't forget that security rules are not filters.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda