Skip to content

Improve efficiency and UX of unique reactions checks #113

@eibex

Description

@eibex

Currently, for each reaction a message has we are checking all users who reacted to it.
This is extremely slow on messages with many reactions and/or people who reacted to them.

A possible solution could be to cache reactions, however, it could lead to problems if the DB isn't in sync anymore due to manual changes, outages, errors, etc.

for existing_reaction in msg.reactions:
if str(existing_reaction.emoji) == reaction:
continue
reaction_users = await existing_reaction.users().flatten()
reaction_users_ids = (reaction_user.id for reaction_user in reaction_users)
if user_id in reaction_users_ids:
await msg.remove_reaction(existing_reaction, user)
# We can safely break since a user can only have one reaction at once
break

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions