php - MySQL photo like count. How to store & count millions of likes for photos? -
php - MySQL photo like count. How to store & count millions of likes for photos? -
i attempting build instagram-like app , not sure how calculate count each photo.
option 1:
user table - user_id - username ... photo table - photo_id - user_id - image_path ... photo_like_relation table - like_id - photo_id - user_id ... so setup able retrieve count after counting results a query like.
"select * photo_like_relation photo_id = x" option 2:
user table - user_id - username ... photo table - photo_id - user_id - image_path - like_count ** ... photo_like_relation table - like_id - photo_id - user_id ... with alternative 2 self explanatory on how retrieve like_count sense messy if there ever lapses in system? perchance like_count total vs count() total of photo_like_relation may not match?
so method better? or there improve method? assume there millions of photos/likes posted in app.
i attempting recreate popular page feature, instagram, grab photos lastly x minutes likes. sense huge burden on scheme loop through of photos posted lastly hour, , count how many records exist in photo_like_relation table respective photo_id.
thoughts? ideas? in advance.
use count() function:
select count(*) photo_like_relation photo_id = x make sure have index on photo_id column, , should efficient.
php mysql sql
Comments
Post a Comment