Skip to content

Instantly share code, notes, and snippets.

@kbirmhrjn
Last active January 4, 2016 02:19
Show Gist options
  • Save kbirmhrjn/8554194 to your computer and use it in GitHub Desktop.
Save kbirmhrjn/8554194 to your computer and use it in GitHub Desktop.
Query Executed
//Debugging through
//Band > music > likes > user
"select * from `band_profile` where `id` = ? limit 1"
"select * from `music_asset` where `music_asset`.`profile_id` = ? and `music_asset`.`profile_type` = ? and `type` = ?"
"select * from `likes` where `likes`.`object_id` = ? and `likes`.`object_type` = ?"
"select * from `likes` where `likes`.`object_id` = ? and `likes`.`object_type` = ? and `user_id` = ? limit 1"
4 query run @ combined
0.00031 + 0.00042 + 0.047 + 0.031 = 0.07873 sec.
//Same Sort of query but using joins,
SELECT * FROM likes
JOIN music_asset ON music_asset.id = likes.object_id
JOIN band_profile ON band_profile.id = music_asset.profile_id
WHERE
band_profile.id = '13' AND music_asset.profile_type = 'band'
AND likes.object_type = 'song'
1 query run @
0.00091 sec
// but considering ORM is easy to use, we still have to add up additional logic to count how many likes each music has & other stuffs
// but the 2nd one I believe will be alot faster if we still further optimized with, rather than selecting (*), we'll select
//only what we need, we don't to waste any memory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment