Introduction
Ben eşsiz bir izleme sistemi uygulamak için en iyi yolu nedir merak ediyorum ... Ben nasıl biliyorum, ben bunu düşünüyorum nasıl açıklayabilir ve eğer herhangi bir hata veya iyileştirmeler işaret etmektedir.
Açıkçası ben bir video kimliği ve (nispeten) benzersiz kullanıcıyı tanımlayan bir şey içeren bir günlüğü tablosunu saklamak zorunda olacak. İlk başta ben başlık istek ve IP kombinasyonu kabul ama basit tutmak ve sadece IP kullanmaya karar verdi. Ayrıca bu şekilde bir kullanıcı farklı bir tarayıcı kullanarak kendi video görüşlerini artırmak olamaz.
This is how I would think to do it:
When a user visits I do a SELECT similar to this:
SELECT 1 FROM tbl_log WHERE IP = $usersip AND video_id = $video_id
if there is no result then I must insert a record
INSERT into tbl_log (IP,video_id) VALUES ($usersip, $video_id)
1'e ve görüşlerini artırmak
SELECT views FROM tbl_video WHERE video_id = $video_id
UPDATE tbl_video SET views = $result['views'] + 1 WHERE video_id = $video_id
Questions
I guess I do not want to have
millions of log records slowing down my site so should I run a cron job to empty the log table once a day?Should I make the views
transactional? (I guess a slightly
depreciated view count is less
important than a slow site because of row locks)Is there a way to reduce the load on the mysql server.... I fear if every view requires an increased view count and an IP log that it will be pretty expensive. I have seen that youtube
and the like do not update the views instantly... do they cache the
updates some how and then run them at once? if so how?How efficient is my system? Can you think of any improvements?