英文:
a lot of data in firebase cloudfirestore (flutter)
问题
I have an app, and I have a list of tools in Cloud Firestore 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 Cloud Firestore, 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?
英文:
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?
答案1
得分: 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, 100,000 reads isn't that much, and perhaps you would cache it client side as well..?
但如果需要处理这个问题,它绝对可能是,一个常见的方法是保留一个包含有关构建小部件所需工具的聚合信息的文档。您可以使用触发器和云函数来保持该文档与您拥有的不同工具的信息同步更新。例如,一个文档,其中包含工具名称的数组,或者工具文档ID指向工具名称的映射。
英文:
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.
答案2
得分: 1
更方便和高效的优化方法是将所有工具的数据存储为Cloud Firestore中单个文档内的地图数组,而不是作为单独的文档。这使用户能够访问一个包含所有工具信息和属性的单个文档,而不必查看多个文档。
这里是一个示例:
因此,您可以轻松地用一个包含200个元素(地图)的数组替代200个文档。
英文:
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:
Thus you can easily replace the 200 documents with one array of 200 elements(maps)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论