Implementation of the database of functions "Most views"

I was wondering how best to implement the “ most viewed ” (like youtube) in my database.

Let me explain that the most viewed feature has improved a bit: Basically I want to list the most visited pages / videos / etc from this day / week / month, see http://www.youtube.com/charts/videos_views for an example.

So, I was wondering how to best implement this function, since I can come up with many different ways to do this, but everyone has their own + and - for them.

Plus, I would also like to hear the comments of various programmers about other ideas of programmers. I would also like to start a good conversation on this topic.

Ps. I especially think about how to calculate the time, say, the most viewed this month, without a huge table that saves each view using datetime. Any idea is welcome.
Pps I use Mysql and PHP, additional tips for these two are very welcome.

+5
source share
5 answers

have the following tables: 1. views 2. views_hourly_summary 3. views_daily_summary 4. views_monthly_summary 5. views_alltime_summary

cron job runs at the following intervals:

  • views_hourly_summary, views_alltime_summary

  • views_daily_summary

  • views_daily_summary

next :

  • , 4 , 3 , :

    item_id, sum (views) from views_hourly_summary concat (left (now() - 3 , 14), '00: 00 ') concat (left (now(), 14), '00: 00') group by item_id

    item_id, count (1) datetime (now() - 4 ) concat (left (now() - 3 , 14), '00: 00 ') datetime > concat (left (now(), 14), '00: 00 ') group by item_id

+3

cookie, . .

, . , , - - , /, , cookie , , IP-/.

. , . , .., - , . , , - / , .

+1

, , ViewCount 1 IP- , .

+1

ItemViews, ( , ). 2 : ItemId ViewCount. , ViewCount 0. , .

. (, Youtube), ItemId, my view .

0

. , , .

, , 5 . db videoID , , , . , , , , / , . , , , . , . , , , 1 , 100 000 , .

Just make sure you have a composite index on [videoId, timestamp] so you can quickly summarize the views.

0
source

All Articles