community-platform icon indicating copy to clipboard operation
community-platform copied to clipboard

[Discussions] Should only fetch comments when discussion is expanded

Open mariojsnunes opened this issue 10 months ago • 2 comments

Is your feature request related to a problem? Please describe. Currently we are fetching all comments as soon as the page is loaded.

Describe the solution you'd like Since Research Update discussions are initially collapsed, we could display only the count and load the comments only when the user expands the comment section.

UPDATE: This not a big deal as the comments are stored as an array. So we only have 1 read per research update. If we want to optimize further, we would need to store the commentCount for research updates.

~~For example, a page that has 3 research updates each one with 10 comments, is currently costing us 3*10=30 reads on the page load. If we only display the count, it would cost only 3 reads (1 per update). Although... if the user loads all comment sections, we would end up with 30+3 reads. But that should be the exception.~~

Additional context Documentation on aggregation query pricing: https://firebase.google.com/docs/firestore/pricing#aggregation_queries

mariojsnunes avatar Apr 22 '24 04:04 mariojsnunes

This sounds good to me, originally I loaded all of the comments to align with the original implementation but now that we have split the discussions out to a separate collection this makes less sense.

Although I am not to sure about the pricing model you have outlined there, my understanding is that we are charged per document.

A Research document consists of an array of Research Updates, but these are not considered separate documents under the Firestore pricing so the Read operations for a Research page with 1000 updates and a Research page with 1 update is equal as 1.

It is the same for the Discussions, we are currently using arrays for storing the comments. So there is a single Read cost for loading a Discussion regardless of how many comments are in the document.

thisislawatts avatar Apr 25 '24 18:04 thisislawatts

Thanks, I've updated accordingly.

mariojsnunes avatar Apr 29 '24 13:04 mariojsnunes

I'm going to pick up the commentCount for research updates issue as we're still getting in a situation where the total count for research article as a whole is different to what the combined count of research updates.

benfurber avatar Jul 06 '24 15:07 benfurber

:tada: This issue has been resolved in version 1.200.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

onearmy-bot avatar Jul 16 '24 13:07 onearmy-bot