[bug] Country flag doesnt change or shows on older comments
See original GitHub issueDescribe the bug It seems that if a user changes or adds their location in the profile it doesnt update their flag on older comments.
To Reproduce Steps to reproduce the behavior:
- Go to how-to
- Leave a comment
- Change location
- Check the comment
- Leave a new comment to see the difference
Expected behavior Ideally, this is in sync across the entire platform. Change your location (flag) > see the change everywhere. in howto, research, comments etc. (This functionaity does seem to work in user profiles. Change location and the flag changes there)
Screenshots Same username, different location
Additional context:
The Community Platform is built on top of a document orientated database called FireStore. As a NoSQL data store it is not simple to perform join queries across multiple collections, for example Howto articles and Users.
Existing behaviour:
- We have the
User
entity, this is where a user can define their location, which we use to render a flag next to their username. - We display the user name in multiple places across the site. Each query/read of a User document is considered a billable unit by Firebase.
To reduce the number of billable operations we copy the location data into each of the following:- Howto article
- Howto comment
- Research article
- Research comment
The implications of this approach are that each time a User changes their location we need to update the location data in each of the documents generated by that User.
The current implementation for syncing this content, is run as a Cloud function triggered by changes in Firestore. Code: https://github.com/ONEARMY/community-platform/blob/master/functions/src/userUpdates/index.ts#L16-L17
The drawbacks with the current approach are:
- Each time we add the username location to a new place in our document store we need to extend our sync mechanism to ensure it stays up to date
- The update method could fail and we have low visibility into this.
- Duplicates the User model data structure in multiple places across the system. This means if we made a change to the User data structure we would have to remember to update; the sync mechanism, all existing documents and UI logic.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
So as discussed on Slack, the current comments structure doesn’t allow for queries such as “all comments for which the userId is X”, which prevents us to update comments for an updated user (unless we query for all howto’s and manually filter, which is inefficient).
The proposed solution is to add to the user info an array of all the howto (and research) id’s where they commented. We still have to discuss how to apply this modification to every existing user. What I’m thinking is creating a one-time running function to update all the users. I’ll be happy to work on this @eliasvelardezft if you’re not able to
@davehakkens hi!! Sorry for the late reply, I’ve been really really busy and haven’t got the time to work on the bug. I started reading through the code when I said I would fix it and I couldn’t easily find the solution and then I simply couldn’t work on it. I’ll try to solve it this weekend, if I can’t I’ll ask for help haha. As for the bounty you’re correct, I hadn’t seen the message. As I said before in the issue comments, I don’t want the bounty! I really like onearmy’s projects (specially project kamp) so I’d like to contribute for free