Commit 555873bb by Scott

Minor optimization of hotness calculation

parent e864eb04
......@@ -42,7 +42,7 @@ function qa_db_hotness_update($firstpostid, $lastpostid = null, $viewincrement =
if (!isset($lastpostid))
$lastpostid = $firstpostid;
$query = "UPDATE ^posts AS x, (SELECT parents.postid, parents.created AS qcreated, COALESCE(MAX(children.created), parents.created) as acreated, COUNT(children.postid) AS acount, parents.netvotes, parents.views FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type='A' WHERE parents.postid>=# AND parents.postid<=# AND LEFT(parents.type, 1)='Q' GROUP BY postid) AS a SET x.hotness=(" .
$query = "UPDATE ^posts AS x, (SELECT parents.postid, parents.created AS qcreated, COALESCE(MAX(children.created), parents.created) as acreated, children.acount, parents.netvotes, parents.views FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type='A' WHERE parents.postid BETWEEN # AND # GROUP BY postid) AS a SET x.hotness=(" .
'((TO_DAYS(a.qcreated)-734138)*86400.0+TIME_TO_SEC(a.qcreated))*# + ' . // zero-point is Jan 1, 2010
'((TO_DAYS(a.acreated)-734138)*86400.0+TIME_TO_SEC(a.acreated))*# + ' .
'(a.acount+0.0)*# + ' .
......
......@@ -453,13 +453,14 @@ if (isset($jumptoanchor))
// 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.
// The lastviewip check is now part of the hotness query in order to bypass caching.
if (qa_opt('do_count_q_views') && !$formrequested && !qa_is_http_post() && qa_is_human_probably() &&
((!$question['views']) || ( // if it has more than zero views
(@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['cookieid'] != $cookieid || !isset($question['cookieid'])) // and different cookieid from the creator
(!$question['views'] || (
// if it has more than zero views, then it must be different IP & user & cookieid from the creator
(@inet_ntop($question['createip']) != qa_remote_ip_address() || !isset($question['createip'])) &&
($question['userid'] != $userid || !isset($question['userid'])) &&
($question['cookieid'] != $cookieid || !isset($question['cookieid']))
))
) {
$qa_content['inc_views_postid'] = $questionid;
......
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