页面视图计数器喜欢上计算器 [英] Page View Counter like on StackOverFlow
本文介绍了页面视图计数器喜欢上计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是实现像他们在这里,每个问题都有一个查看计数器网站上的那些页面视图计数器的最佳方式?
What is the best way to implement the page view counter like the ones they have here on the site where each question has a "Views" counter?
代管性能和可伸缩性的问题。
Factoring in Performance and Scalability issues.
推荐答案
计数器优化我这样的作品:
The counter i optimized works like this:
UPDATE page_views SET counter = counter + 1 WHERE page_id = x
if (affected_rows == 0 ) {
INSERT INTO page_views (page_id, counter) VALUES (x, 1)
}
在运行2查询第一种观点这样一来,其他视图只需要1查询。
This way you run 2 query for the first view, the other views require only 1 query.
这篇关于页面视图计数器喜欢上计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文