Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added capability to mention users by username #3253

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

harmitgoswami
Copy link
Collaborator

Fix #2625

Added functionality for mentioning users by typing their username instead of only by display name. This feature was achieved by modifying the /get-users/ API to return the usernames of all UserProfile objects in addition to the preexisting fields. The suggestedUsers filter function was modified to first check for a matching username (if it exists), then checking for a matching display name.

To reproduce results: After starting up the server, navigate to any team/project. Select any string that has an existing translation. Click the "COMMENT" button, and then inside the text editor field, type @[any string of letters] to display a list of users whose display name or username contains that string of letters. If you know a specific user's username, try typing their full username or a subset of it, and their profile will appear just as if you typed their display name instead.

image

image

@@ -685,6 +685,7 @@ def get_users(request):
"gravatar": u.gravatar_url(44),
"name": u.name_or_email,
"url": u.profile_url,
"username": u.profile.username,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will result in N additional DB queries, where N is the number of users (currently close to 20k on production), which makes the /get-users/ request quite slow compared to its current performance.

This happens because the username is stored in a separate table (UserProfile rather than User). The issue can be mitigated by using prefetch_related().

You can debug DB queries using debug_sql().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a million times faster! Thank you for pointing that out

Copy link
Collaborator

@mathjazz mathjazz left a comment

Choose a reason for hiding this comment

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

Excellent job!

@mathjazz mathjazz merged commit 5bb0877 into mozilla:main Jun 7, 2024
6 checks passed
@harmitgoswami harmitgoswami deleted the username-mention branch June 7, 2024 18:45
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.

Add ability to mention users using their username
2 participants