Currently I check to see if a user has viewed a video yet or not by checking if that user has recorded a view in our views table.
The query looks like this:
SELECT EXISTS(SELECT 1 FROM views WHERE videoid=:vid AND userid=:uid)
When displaying a page with video thumbnails, we overlayed "Seen", if the user has already watched this video, similar to the functionality on youtube.
The problem is that this query is rather slow to compute, as the views table has a large number of rows - 40 or 50ms. If a page has, say 60 video thumbnails displayed, there are 3 full seconds of SQL delay before the page can be rendered.
Is my problem architectural, or can I do something to speed the execution of the query up?
viewstable have an index that covers videoid and userid?views(idint(11) NOT NULL AUTO_INCREMENT,videoidint(11) NOT NULL,ipvarchar(32) NOT NULL,useridint(11) NOT NULL,whendatetime NOT NULL, PRIMARY KEY (id) )