-
Notifications
You must be signed in to change notification settings - Fork 35
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
Chore/fix user query #2296
Chore/fix user query #2296
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
// Cache lookup | ||
// if long url does not exist, throws error | ||
const longUrl = await this.getLongUrlFromCache(shortUrl) | ||
return !longUrl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: small optimisation but unnecessary
return !longUrl | |
return true |
edit should be false
OOPS
const url = await Url.findOne({ | ||
where: { shortUrl }, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/nit/micro-optimization: since we only care for an exists
, you could reduce the selection to just the shortUrl
field. Otherwise the query seems to be sent like this atm (according to the traces):
SELECT shortUrl, longUrl, state, isFile, contactEmail, description, source, tagStrings, createdAt, updatedAt, userId FROM urls WHERE url . shortUrl = ?
const url = await Url.findOne({ | |
where: { shortUrl }, | |
}) | |
const url = await Url.findOne({ | |
attributes: ['shortUrl'], | |
where: { shortUrl }, | |
}) |
Problem
Optimising our current query to check if short link exists. Previous query was doing an unnecessary join on the users table, causing the query duration to spike.
Solution
Replaced query to only check in urls table instead of joining urls with user table.
Before & After Screenshots
BEFORE:
![Screenshot 2024-03-18 at 5 44 04 PM](https://private-user-images.githubusercontent.com/39231249/313625575-3c1f5c1d-786f-4c42-b5e2-859eb46d60ca.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMTc3NTYsIm5iZiI6MTcyMjExNzQ1NiwicGF0aCI6Ii8zOTIzMTI0OS8zMTM2MjU1NzUtM2MxZjVjMWQtNzg2Zi00YzQyLWI1ZTItODU5ZWI0NmQ2MGNhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI3VDIxNTczNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ4OWU5OTUxZjRjMWMzNzY0ZWI3NDNjNmJjNThlN2RiNmJhMDc3MTBlMTM5OTAyYjRhMDNmYjU3NzJlYTBjZmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.HiDx_eOLy-g0PI3rosEtAwJLR-ac2OnYgLr5ICB2oY0)
AFTER:
![Screenshot 2024-03-18 at 5 35 38 PM](https://private-user-images.githubusercontent.com/39231249/313623003-ee5b523c-86ab-4cfe-9974-f83e3a984a12.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMTc3NTYsIm5iZiI6MTcyMjExNzQ1NiwicGF0aCI6Ii8zOTIzMTI0OS8zMTM2MjMwMDMtZWU1YjUyM2MtODZhYi00Y2ZlLTk5NzQtZjgzZTNhOTg0YTEyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI3VDIxNTczNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTllYzM5ODMxMjQzYzY1ZTI4N2QxZTFkYWFmZDIzNTM5MjUwMTBhYjkzYTc4ZDRlZjhlMjg4ODYwNGI1ZWE0MDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.6XiM8ZmxTFitxu1H0k_wKWEdwW75lFUs5pKUSrkR1S8)
Tests
E2E Manual tests