1
votes

I have one question for the store of big list in firestore (using flutter). I have a database like this:

--DataBase

------Post

---------Comment

And each post/comment must store the list of user who liked/add fav.

In a first time i have create two list in my collection Post/Comment Solution1

But I know that the solution is not good, because the size of a document is limited So I thought about a second solution, which consists in adding a collection "userData" in the Post / Comment collections and for each user create a document containing the data. Like this : Solution2

But the second solution bothers me. Because when the user loads the Post list and the comment List, for each post/comment I will do an additional query to find if the user already likes/add fav. So if I have 50 comments per post and if the user looks at 100 posts, it generates 10,000 requests (100 * 50 * 2), and that per user.

I am afraid that the price of these requests does not cover the gains of the application.

So, is the second solution the recommended solution? Is there another solution ?

Thanks

1
You only need to read the userData document for the current user, and check their isFav field, so that takes just one document read per post/comment. Or am I missing something? Seeing it in code would probably make that clearer. - Frank van Puffelen
Thank you for your answer ! It takes a request to retrieve the post/comment and a request to retrieve the userData. So two requests in total per post/comment. I can limit the number of requests by retrieving several post/comment with only one query but each comment/post will still require a query for userData. Then it may be the only solution, I just wanted to be sure - montauvergne
Instead of do 1 query for get 10 post. I make 1 query for get 10 post and 1 query per post for get userData. So instead of do 1 query, I do 11 query. - montauvergne

1 Answers

0
votes

I would use subcollections for this and simply not display the list of comments (or just show the latest comment) when the user is going through the list of posts. Once the user interacts with a post then paginate or create an infinite scroll of the comments collection using query-cursors