Commit fbb97ca1 by Scott

Fix view count update with caching

parent cc379da3
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
function qa_db_hotness_update($firstpostid, $lastpostid=null, $viewincrement=false) function qa_db_hotness_update($firstpostid, $lastpostid=null, $viewincrement=false)
/* /*
Recalculate the hotness in the database for posts $firstpostid to $lastpostid (if specified) Recalculate the hotness in the database for posts $firstpostid to $lastpostid (if specified)
If $viewincrement is true, also increment the views counter for the post, and include that in the hotness calculation If $viewincrement is true, also increment the views counter for the post (if different IP from last view),
and include that in the hotness calculation
*/ */
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
...@@ -44,7 +45,8 @@ ...@@ -44,7 +45,8 @@
'(a.acount+0.0)*# + '. '(a.acount+0.0)*# + '.
'(a.netvotes+0.0)*# + '. '(a.netvotes+0.0)*# + '.
'(a.views+0.0+#)*#'. '(a.views+0.0+#)*#'.
')'.($viewincrement ? ', x.views=x.views+1, x.lastviewip=$' : '').' WHERE x.postid=a.postid'; ')'.($viewincrement ? ', x.views=x.views+1, x.lastviewip=$' : '').
' WHERE x.postid=a.postid'.($viewincrement ? ' AND (x.lastviewip IS NULL OR x.lastviewip!=$)' : '');
// Additional multiples based on empirical analysis of activity on Q2A meta site to give approx equal influence for all factors // Additional multiples based on empirical analysis of activity on Q2A meta site to give approx equal influence for all factors
...@@ -59,8 +61,10 @@ ...@@ -59,8 +61,10 @@
qa_opt('hot_weight_views')*4000, qa_opt('hot_weight_views')*4000,
); );
if ($viewincrement) if ($viewincrement) {
$arguments[]=@inet_pton(qa_remote_ip_address()); $ipbin = @inet_pton(qa_remote_ip_address());
array_push($arguments, $ipbin, $ipbin);
}
qa_db_query_raw(qa_db_apply_sub($query, $arguments)); qa_db_query_raw(qa_db_apply_sub($query, $arguments));
} }
......
...@@ -446,7 +446,8 @@ ...@@ -446,7 +446,8 @@
); );
// Determine whether this request should be counted for page view statistics // Determine whether this request should be counted for page view statistics.
// The lastviewip check is now in the hotness query in order to bypass caching.
if ( if (
qa_opt('do_count_q_views') && qa_opt('do_count_q_views') &&
...@@ -454,7 +455,6 @@ ...@@ -454,7 +455,6 @@
(!qa_is_http_post()) && (!qa_is_http_post()) &&
qa_is_human_probably() && qa_is_human_probably() &&
( (!$question['views']) || ( // if it has more than zero views ( (!$question['views']) || ( // if it has more than zero views
( (@inet_ntop($question['lastviewip'])!=qa_remote_ip_address()) || (!isset($question['lastviewip'])) ) && // then it must be different IP from last view
( (@inet_ntop($question['createip'])!=qa_remote_ip_address()) || (!isset($question['createip'])) ) && // and different IP from the creator ( (@inet_ntop($question['createip'])!=qa_remote_ip_address()) || (!isset($question['createip'])) ) && // and different IP from the creator
( ($question['userid']!=$userid) || (!isset($question['userid'])) ) && // and different user from the creator ( ($question['userid']!=$userid) || (!isset($question['userid'])) ) && // and different user from the creator
( ($question['cookieid']!=$cookieid) || (!isset($question['cookieid'])) ) // and different cookieid from the creator ( ($question['cookieid']!=$cookieid) || (!isset($question['cookieid'])) ) // and different cookieid from the creator
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment