FriendsOfFlarum / gamification

Add upvotes, downvotes, and ranks to your Flarum Community
https://discuss.flarum.org/d/20671-friendsofflarum-gamification
MIT License
36 stars 17 forks source link

fix: load discussion voting info on BasicDiscussionSerializer #76

Closed davwheat closed 2 years ago

davwheat commented 2 years ago

Changes proposed in this pull request: When displaying the vote box next to discussions in the DiscussionList, sometimes vote info does not update when clicking to toggle a vote. This is because it pulls data from discussion.votes rather than discussion.firstPost.votes, while UpdatePostController (which handles the vote setting) only returns a basicly-serialized discussion as an included model in the API response, meaning that the vote count on the discussion itself does not get updated in the frontend.

Reviewers should focus on:

What performance impact does this bring? Is it significant?

Confirmed

imorland commented 2 years ago

I've not run it locally, but I think it'll be ok from a performance perspective. At the very least it won't be much of a performance hit, as the same data is added to the DiscussionSerializer anyway. BasicDiscussionSerializer is used far less generally.

My only question is, do we need to add the same data to both serializers, or does DiscussionSerializer inherit the data already added by BasicDiscussionSerializer? From memory, I think it does, but if you have it locally it would be worth a quick double check, as we could remove the additional extender call?