Skip to content

✨(backend) add limit on distinct reactions per comment#1978

Open
maboukerfa wants to merge 2 commits intosuitenumerique:mainfrom
maboukerfa:feat/add-max-reaction
Open

✨(backend) add limit on distinct reactions per comment#1978
maboukerfa wants to merge 2 commits intosuitenumerique:mainfrom
maboukerfa:feat/add-max-reaction

Conversation

@maboukerfa
Copy link
Contributor

Purpose

The current implementation allows users to add an unlimited number of reactions per comment.
Because the /threads endpoint is called on document load, having multiple comments with
thousands of reactions each could significantly impact page load performance.

Screenshot 2026-03-11 at 00 16 56

Proposal

Implement a configurable limit (default: 15) on the number of distinct emoji reactions per comment.

  • Backend validation ensures the limit cannot be exceeded via API
  • Frontend disables reaction buttons when limit is reached
Screen.Recording.2026-03-11.at.00.21.53.mov

@maboukerfa maboukerfa force-pushed the feat/add-max-reaction branch 4 times, most recently from 0399104 to af0eeff Compare March 10, 2026 23:30
@lunika lunika requested review from AntoLC and lunika March 11, 2026 07:05
Copy link
Member

@lunika lunika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably add reactions in the select_related objects in the queryset property to avoid N+1 query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where you set it to 10.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_COMMENT

Implement 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>
@maboukerfa maboukerfa force-pushed the feat/add-max-reaction branch from af0eeff to 390085d Compare March 11, 2026 21:57
@maboukerfa maboukerfa requested a review from lunika March 11, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants