Apply user local changes to local firestore data.

44 views
Skip to first unread message

Michal Kubizna

unread,
Jan 31, 2023, 2:16:28 PMJan 31
to google-cloud-firestore-discuss

Use case:
I’d like to create a comment section. A real-time listener doesn’t work with pagination in a dynamic collection like that since the moment comments are deleted or added the start value changes for each listener resulting in an inconsistent state.

A solution is to implement pagination using one-time get calls but that forces me to implement my own caching or state management solution to update the local data on the user’s device when they make changes (e.g add, delete, or like a comment). It’s a shame because Firestore implements its own caching solution and listening to the local cache would update fetched data with the user’s updates automatically.

Is there a way easily do it in Firestore? 

Thank you 

Cheryl Lin

unread,
Feb 1, 2023, 6:31:04 PMFeb 1
to google-cloud-firestore-discuss
Hi Michal,

In your case, snapshot reads is still an feasible solution even it leads to inconsistent state. Since in the high volume scenario, usually this kind of inconsistent buffer is acceptable. If you really want to guarantee the behaviour, currently you have to implement the cache with get by yourself.

Michal Kubizna

unread,
Feb 2, 2023, 5:50:28 PMFeb 2
to google-cloud-firestore-discuss
Hello,

Thank you for your response. I was wondering if maybe I could solve this by attaching a Firestore listener to each retrieved document id. Would that affect the performance of the app? If a user navigates more than 4 or 5 pages, it would result in 40 or 50 listeners being attached. Is this a feasible solution?

Thank you

Cheryl Lin

unread,
Feb 4, 2023, 9:15:28 PMFeb 4
to google-cloud-firestore-discuss

Please allow me to better understand your case. In my opinion, it makes sense to attach a Firestore listener (snapshot read) to each of topic, but you might not want to attach one listener to every comment.

Michal Kubizna

unread,
Feb 8, 2023, 6:46:37 AMFeb 8
to google-cloud-firestore-discuss
Hi Cheryl, thank you for your response. 
I am confused because this answer by a former Googler says that listeners are cheap and there is no hard limit. - https://stackoverflow.com/questions/56213903/max-number-of-document-realtime-listeners/56213933#comment132922795_56213933
But the firebase docs say to keep - Keep the number of snapshot listeners per client under 100. - https://firebase.google.com/docs/firestore/best-practices#realtime_updates

Cheryl Lin

unread,
Feb 8, 2023, 12:58:47 PMFeb 8
to google-cloud-firestore-discuss
Hi,

The above two statements are both true. We don't have an hard limit but in order to achieve best performance, it is suggested to keep the number low per client.
Reply all
Reply to author
Forward
0 new messages