Repository navigation
perf: index account.username used by every authenticated request - #380
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: taylor.curran <taylorcurranagtc@gmail.com>
Author
There was a problem hiding this comment.
✅ Devin Review: No Issues Found
Devin Review analyzed this PR and found no bugs or issues to report.
Custom reviewers
- 🧪 Test 2 reviewer: no findings · View
- 🚩 TD Enterprise Architecture: no findings · View
- 👁️ TD Information Security: no findings · View
- 🧠 TD French Language (Bill 96): no findings · View
- ⏱️ TD API Contracts: no findings · View
- 🧹 Henry's Style Guide: no findings · View
- ✨ iOS Smoketester: no findings · View
- ✨ Blast Radius Reviewer: no findings · View
- 🛡️ API Security Reviewer: no findings · View
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AccountRepository.findByUsernameruns on every authenticated request (login vialoadUserByUsername,GET /dashboard,GET /transactions,POST /deposit|/withdraw|/transfer, and the duplicate check in/register), butaccount.usernamehad no index, so each lookup was a full table scan (EXPLAIN:type=ALL, 198,600 rows at 200k accounts).With
spring.jpa.hibernate.ddl-auto=update, Hibernate creates it at startup (create index idx_account_username on account (username));EXPLAINbecomestype=ref,key=idx_account_username, rows=1. Non-unique on purpose, so startup can't fail on a database that already holds duplicate usernames.Before / after (local, no Datadog service for this app)
MySQL 8.0 (repo blueprint container), 200,001 accounts, 400,050 transactions (50 for the bench user).
bench.pywith 20 warm-up requests, then n=500, c=10, logged-inJSESSIONID. Two runs each; second runs swapped the index on the same running app.Repro
docker run -d --name bankapp-mysql -e MYSQL_ROOT_PASSWORD='Test@123' -e MYSQL_DATABASE=bankappdb -p 3306:3306 mysql:8.0 --default-authentication-plugin=mysql_native_password./mvnw -DskipTests package && java -jar target/bankapp-0.0.1-SNAPSHOT.jarcurl -X POST localhost:8080/register -d 'username=bench&password=benchpw'INSERT INTO account ... SELECT ... CONCAT('user', n)plus 50 transactions forbenchand 400k for the others.BENCH_PORT=8080 BENCH_HEADERS="Cookie: JSESSIONID=<sid>" python3 bench.py /dashboard 500 10(same for/transactions).Cost
innodb_index_stats). It builds in 0.27 s at first startup on that table.Response equivalence
The rendered
/dashboardand/transactionsHTML for the bench user is byte-identical before and after, apart from per-request UUIDs. That includes all 50 transaction rows.Tests
./mvnw testagainst the MySQL container:Tests run: 1, Failures: 0, Errors: 0, Skipped: 0,BUILD SUCCESS.The touched entity comes from the original author's initial commit (
goldencat, e6208f7).Implemented in session Find and fix next slow path in new repo
Review with Devin · Open in Devin Desktop
Note
Devin errored when opening this Pull Request as taylorcurranpython.
As a fallback, Devin opened this PR as itself.