skip to Main Content

i have an app, and i have a list of tools in cloudfirestore firebase, but there are 200+ data in there

so users have to select whatever tool they want to select, possibly users can select up to 20 tools per user.

I use the dropdown (https://pub.dev/packages/custom_searchable_dropdown) to see a list of 200 tools, I can even search for the tool the user wants.

the question is, every time 1 user sees the list, there are 200 read data in cloudfirestore, which is only 1 user. Now I have about 500 active users who choose tools every day. of course this would be a waste of money for me as a developer where firebase sets a price per 100,000 documents.

can anyone solve my problem here?

2

Answers


  1. I’m sure there are many ways to handle it. Starting with the first thing to consider is if it is worth optimizing away… maybe in the grand scheme of things, 100000 reads isn’t that much, and perhaps you would cache it client side as well..?

    But if it is something to handle, which it absolutely might be, a common thing is to keep one document which has the aggregate information about the tools needed to just build that widget. You could use triggers and cloud functions to keep that document up to date with the different tools you have. I.e. a document that has an array with say the tool names, or a map where tool doc id point to tool name.

    Login or Signup to reply.
  2. A more convenient and efficient approach to optimization is to store all the tools’ data as an array of maps within a single document in Cloud Firestore, rather than as separate documents. This enables users to access a single document that contains all the tools’ information and properties, rather than having to read through multiple documents.
    Here is an example:

    enter image description here

    Thus you can easily replace the 200 documents with one array of 200 elements(maps)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search