Perf : Save ratings count in notices entities #408
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For each display of notices list in back-office and every call of the API with notices info or notices list, we are counting the number of ratings for each type of rating … No wonder why this was getting slow and consuming up to 1 GB of memory just to show 20 notices in back-office !
What I did here is to store the count of
badged
,display
,unfold
,clicked
,liked
, 'dislikedand
dismissedevents directly in
Noticeentities, and update the corresponding count every time a rating is
POST`ed.Showing the same page now consumes approx 15-20MB of memory (tested with production database) … back to normal.
For now, with the added index, the rating
POST
is quick enough (400 ms), so I left the bus synchronous, but later, it would be possible to make it asynchronous, and event to group updates.Note that this breaks a bit the single source of truth, but it also shows the way to CQRS if you think about it :-) …
@MaartenLMEM @Etienne-DisMoi One nice side effect is that you can now sort the notices by ratings in the back-office. (I also changed some table headers to emojis to save some space)
It would be possible to do the same with
relayersCount
if this proves useful.