I am applying an application that monitors the number of occasions a publish is seen. But Let me have a 'smart' method of keeping track. What this means is, I'd rather not boost the view counter must be user refreshes his browser.

And So I made the decision to simply boost the view counter if IP and user agent (browser) are unique. That is working to date.

However I figured. If Youtube, does it by doing this, and they've several videos with 1000's as well as countless sights. This indicates their sights table within the database could be excessively populated with IP's and user agents....

That can bring me towards the assumption their video table includes a counter cache for sights (i.e. views_count). What this means is, whenever a user clicks a relevant video, the IP and user representative is saved. Plus, the counter cache column within the video table is elevated.

Whenever a video is clicked on. Youtube will have to query the sights table and count the amount of records. Will not this affect performance drastically?

Is the way they get it done? Or it is possible to better way?

If you wish to store all of the IP's and browsers, then make certain you've enough DB space for storage, add a catalog and that is it. Otherwise, you'll be able to make use of the rails session to keep their email list of videos that the user has visited, and just increment the vista_count attribute of the video when he's going to a brand new video.

To begin with, afaik, youtube uses BigTable, so do not concern yourself about querying the count, we do not be aware of exact structure from the database anyway.

Presuming that you're on the relational model, produce a column view_count, but don't update it on every refresh. Record the visists and periodically update the cache.

Also, you will get hash from IP, browser, date and then any additional information you're using to identify if this sounds like a special view, and don't keep whole data.

Also, you should use session/cookie to record the vista being seen. Because it will expire, it will not be such memory problem - I do not believe anybody is viewing 1000 of videos in a single session