php - Keeping track of users and photos they've viewed -


i have high traffic site lots of photos on , trying track photo each user has viewed.

my first instinct sql table 2 columns: user_id & photo_id. but, wouldn't scale traffic level, , table unmanageable quickly.
recommendations anoher solution, either sql or nosql (mongodb,couch,redis,...)

my code php if matters.

thanks!

edit there 10s of millions of views day.

edit don't need know total times user viewed particular photo, whether been viewed @ user

your best bet create collection { _id:generated automagically, pictureid, viewerid }

with find( pictureid, viewerid ).limit(1) , index on pictureid and viewerid make checking super ultra fast level 99. important set index. use find().limit(1) because faster findone, @ least current benchmarks.

why not have 1 entry per user array of viewed images? because searching through array slower searching whole document in collection. 10 million images? no problem. mongodb shines. designed scale big-ass databases yours. long documents less 16 mb, , 3 properties, :) have little worry about.

when delete image, db.viewed.remove( { pictureid : pictureid } ) , remove relating image.

db.viewed.remove( { viewerid : viewerid } ) when remove user! don't when user deletes image or account. @ maintenance time or say, once hour. create collection pendingremovingimages , pendingremovingusers store things want removed. check $in perform bulk removal images and/or users.

i find question exciting , feel should go in direction.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -