community-platform
community-platform copied to clipboard
[Cloud function]: Daily sync of research meta-data
Due to the move to discussion documents holding the comments for each research update and changing comments from being deleted from the DB to be updated to _deleted
, it's much more common and noticiable that the comment count stored for each research articles (totalCommentCount
) gets out of sync with the reality.
Solution: Accept that certain changes in data will be fallible and have a cloud function that runs daily for research that:
- Identifies all the currently not
_deleted
and published research articles. - Identifies all the published and not
_deleted
updates for each article. - Identifies discussion document for each research update (found through the
_id
of an update being thesourceId
of the discussion). - Count the not _deleted comments for the discussion.
That should then give a total that can be set as the totalCommentCount
for the research.