✨(backend) add limit on distinct reactions per comment#1978
Open
maboukerfa wants to merge 2 commits intosuitenumerique:mainfrom
Open
✨(backend) add limit on distinct reactions per comment#1978maboukerfa wants to merge 2 commits intosuitenumerique:mainfrom
maboukerfa wants to merge 2 commits intosuitenumerique:mainfrom
Conversation
0399104 to
af0eeff
Compare
lunika
reviewed
Mar 11, 2026
Member
lunika
left a comment
There was a problem hiding this comment.
I only focus on the backend part.
If possible, can you split in 2 commits ? A first one for the backend and a second one for the frontend ?
Thank you so much for your contribution
| not models.Reaction.objects.filter( | ||
| comment=comment, emoji=emoji | ||
| ).exists() | ||
| and comment.reactions.count() >= settings.REACTIONS_MAX_PER_COMMENT |
Member
There was a problem hiding this comment.
You should probably add reactions in the select_related objects in the queryset property to avoid N+1 query.
Contributor
Author
There was a problem hiding this comment.
I changed it to
queryset = (
models.Comment.objects.select_related("user")
.prefetch_related("reactions__users")
.all()
)This loads each comment’s user, its related reactions, and the users who reacted.
| def test_create_reaction_exceeds_maximum(): | ||
| """ | ||
| Users should not be able to add more than REACTIONS_MAX_PER_COMMENT | ||
| (here we set it to 10) distinct emoji reactions to a comment. |
Member
There was a problem hiding this comment.
I don't see where you set it to 10.
Contributor
Author
There was a problem hiding this comment.
It was hardcoded. I’ve imported settings in the test files and used the REACTIONS_MAX_PER_COMMENT var:
max_reactions = settings.REACTIONS_MAX_PER_COMMENTImplement a configurable limit (default: 15) on the number of distinct emoji reactions per comment. - Backend validation ensures the limit cannot be exceeded via API Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
Prevent users from adding more reactions once the per-message limit has been exceeded. It Disables reaction buttons when limit is reached Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
af0eeff to
390085d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
The current implementation allows users to add an unlimited number of reactions per comment.
Because the
/threadsendpoint is called on document load, having multiple comments withthousands of reactions each could significantly impact page load performance.
Proposal
Implement a configurable limit (default: 15) on the number of distinct emoji reactions per comment.
Screen.Recording.2026-03-11.at.00.21.53.mov