mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-25 15:38:56 +00:00
The old code would make one query for all the urls and revisions, then loop and individual query each bin. If the user has 100+ bins, then it gets slow and expensive because we can't group these queries together. I've changed this so that the query simply joins the owners and sandbox table, so instead of *just* getting the url and revision as previously, we're now getting all the data in one request. I've also removed the sorting as this happens entirely in the code. The query, live for my own homepage is 1.13 seconds. I'm hoping therefore the sum change of this update will reduce the 24 seconds down to 1-2 seconds. One additional change I'd like would be to only make the request for the `/list` page if the user really goes there, or perhaps hovers over their home link - as a preemptive request - so we're not always making the request for their home urls.
25 lines
2.3 KiB
JSON
25 lines
2.3 KiB
JSON
{
|
|
"getBin": "SELECT * FROM `sandbox` WHERE `url`=? AND `revision`=? LIMIT 1",
|
|
"getLatestBin": "SELECT * FROM `sandbox` WHERE `url`=? ORDER BY `revision` DESC LIMIT 1",
|
|
"setBin": "INSERT INTO `sandbox` (`javascript`, `css`, `html`, `created`, `last_viewed`, `url`, `revision`, `streaming_key`, `settings`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
"setBinPanel": "UPDATE `sandbox` SET `:panel`=?, `settings`=?, `created`=? WHERE `url`=? AND `revision`=? AND `streaming_key`=? AND `streaming_key`!='' AND `active`='y'",
|
|
"binExists": "SELECT id FROM `sandbox` WHERE `url`=? LIMIT 1",
|
|
"getUser": "SELECT * FROM `ownership` WHERE `name`=? LIMIT 1",
|
|
"getByEmail": "SELECT * FROM `ownership` WHERE `email`=? LIMIT 1",
|
|
"setUser": "INSERT INTO `ownership` (`name`, `key`, `email`, `last_login`, `created`, `updated`) VALUES (?, ?, ?, ?, ?, ?)",
|
|
"touchLogin": "UPDATE `ownership` SET `last_login`=? WHERE `name`=?",
|
|
"updateUserKey": "UPDATE ownership SET `key`=?, `updated`=? WHERE `name`=?",
|
|
"upgradeUserKey": "UPDATE ownership SET `key`=?, `created`=?, `updated`=? WHERE `name`=?",
|
|
"setBinForUser": "INSERT INTO `owners` (`name`, `url`, `revision`, `last_updated`) VALUES (?, ?, ?, ?)",
|
|
"getBinsByUser": "SELECT s.* FROM `owners` as o, `sandbox` s WHERE o.url=s.url and o.revision=s.revision and o.name=?",
|
|
"getBinByUrlAndRevision": "SELECT * FROM `sandbox` WHERE `url`=? AND `revision`=? LIMIT 1",
|
|
"getLatestBinForUser": "SELECT `url`, `revision` FROM `owners` WHERE `name`=? AND `last_updated` != 0 ORDER BY `last_updated` DESC LIMIT 1",
|
|
"touchOwnership": "UPDATE `owners` SET `last_updated`=? WHERE `name`=? AND `url`=? AND `revision` = ?",
|
|
"updateUserEmail": "UPDATE ownership SET `email`=?, `updated`=? WHERE `name`=?",
|
|
"getUserByEmail": "SELECT * FROM `ownership` WHERE `email`=? LIMIT 1",
|
|
"getUserForForgotToken": "SELECT `ownership`.*, expires FROM `ownership` INNER JOIN `forgot_tokens` ON `name` = `owner_name` WHERE `token` = ? AND `forgot_tokens`.`expires` >= ?",
|
|
"setForgotToken": "INSERT INTO `forgot_tokens` (`owner_name`, `token`, `expires`, `created`) VALUES (?, ?, ?, ?)",
|
|
"deleteExpiredForgotToken": "DELETE FROM `forgot_tokens` WHERE `expires` <= ? OR `token`=? OR `owner_name`=?",
|
|
"reportBin": "UPDATE `sandbox` SET `reported`=? WHERE `url`=? AND `revision`=? AND `active`='y'"
|
|
}
|