Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce Firestore reads in a flutter App?

Note: I am a newbie in flutter, Android and Firebase.

So, I have a logo Maker App, the assets(PNG Images) such as the face, hat etc. are saved in the firestore Database. I have a total of 71 documents in my database currently.

Currently, I use cached_network_image plugin. With this plugin, the image will be read-only one time for a single user. Since from next time image will be retrieved from cache Storage. But the retrieval of the title of the image is still a problem.

Still, for a single user, I get around 100 reads! This is the schema of my database.

Kinda Obvious different collection for different parts, and one document for one image. Database Schema

Using StreamBuilder to retrieve data,

Code code 2

Is there any way I can reduce the number of read request by either code or changing database schema or something else?

like image 991
Raj Dhakad Avatar asked Aug 24 '19 02:08

Raj Dhakad


1 Answers

One option you might want to consider is combining things into fewer documents.

I'm not exactly sure how you're planning on using this data from the database, but it seems like your main use case is "read in everything from the faces collection and display it in a list". If that's the case (and these records are relatively small) do you need to put every face in a separate document? If you're not going to paginating this list, or searching for and retrieving subsets of this collection, you could just create a JSON object containing all of your face data and put that into a single document.

Do that for each of your other records, and you've gone from about 71 documents to 7. That's a 10x savings!

like image 72
Todd Kerpelman Avatar answered Oct 06 '22 01:10

Todd Kerpelman