perf: optimize login queries by combining username and email lookups#87
perf: optimize login queries by combining username and email lookups#87Tugamer89 wants to merge 1 commit into
Conversation
Optimized the `get_user_by_username_or_email` method by combining two separate database lookups into a single query using SQLAlchemy's `or_` operator. This reduces database hits, particularly for users logging in via username, as it prevents executing the email query first and then falling back to the username query. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|



What
Optimized the
get_user_by_username_or_emailmethod by combining two separate database lookups into a single query using SQLAlchemy'sor_operator.Why
Previously, the code executed two sequential database queries to find a user: first checking by email, and if that failed, checking by username. This caused unnecessary database round-trips for users logging in with their usernames.
Impact
Reduces database queries by 50% for users authenticating with their usernames, decreasing overall login latency and lowering database load under high concurrency.
Measurement
A local script was created to verify that users can successfully register and login with either an email or a username, ensuring that both authentication flows function identically with the single optimized query.
PR created automatically by Jules for task 13641137495173267505 started by @Tugamer89