Skip to content

perf: optimize login queries by combining username and email lookups#87

Open
Tugamer89 wants to merge 1 commit into
mainfrom
perf-optimize-login-query-13641137495173267505
Open

perf: optimize login queries by combining username and email lookups#87
Tugamer89 wants to merge 1 commit into
mainfrom
perf-optimize-login-query-13641137495173267505

Conversation

@Tugamer89

Copy link
Copy Markdown
Owner

What

Optimized the get_user_by_username_or_email method by combining two separate database lookups into a single query using SQLAlchemy's or_ 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

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant