Commit 694c2eaf by Scott

Refactor hotness code

parent 788f260c
......@@ -368,7 +368,10 @@ function qa_output_content($qa_content)
*/
function qa_do_content_stats($qa_content)
{
if (isset($qa_content['inc_views_postid'])) {
if (!isset($qa_content['inc_views_postid'])) {
return false;
}
require_once QA_INCLUDE_DIR . 'db/hotness.php';
qa_db_increment_views($qa_content['inc_views_postid']);
......@@ -377,9 +380,6 @@ function qa_do_content_stats($qa_content)
}
return true;
}
return false;
}
......
......@@ -40,19 +40,22 @@ function qa_db_increment_views($postid)
/**
* 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 (if different IP from last view),
* and include that in the hotness calculation
* @param $firstpostid
* @param $lastpostid
* @param bool $viewincrement
* @return mixed
* Recalculate the hotness in the database for one or more posts.
*
* @param $firstpostid First post to recalculate (or only post if $lastpostid is null).
* @param $lastpostid Last post in the range to recalculate.
* @param bool $viewincrement Deprecated - view counter is now incremented separately. Previously, would increment the post's
* views and include that in the hotness calculation.
* @return void
*/
function qa_db_hotness_update($firstpostid, $lastpostid = null, $viewincrement = false)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
if (qa_should_update_counts()) {
if (!qa_should_update_counts()) {
return;
}
if (!isset($lastpostid))
$lastpostid = $firstpostid;
......@@ -77,5 +80,4 @@ function qa_db_hotness_update($firstpostid, $lastpostid = null, $viewincrement =
);
qa_db_query_raw(qa_db_apply_sub($query, $arguments));
}
}
......@@ -203,7 +203,7 @@ return array(
'recalc_categories_note' => ' - for post categories and category counts',
'recalc_categories_recounting' => 'Recounting questions for ^1 of ^2 categories...',
'recalc_categories_updated' => 'Recalculated for ^1 of ^2 posts...',
'recalc_hotness_q_view_note' => 'Slightly more efficient if disabled, but hotness values will become out of date if views are given higher importance in settings',
'recalc_hotness_q_view_note' => 'May slightly improve page speed if disabled, but hotness values will become out of date if views are included in hotness settings',
'recalc_points' => 'Recalculate user points',
'recalc_points_complete' => 'All user points were successfully recalculated.',
'recalc_points_note' => ' - for user ranking and points displays',
......
......@@ -429,27 +429,30 @@ if ($question['basetype'] == 'Q') {
? qa_lang_html_sub_split('question/1_answer_title', '1', '1')
: qa_lang_html_sub_split('question/x_answers_title', $countfortitle);
if ($microdata)
if ($microdata) {
$split['data'] = '<span itemprop="answerCount">' . $split['data'] . '</span>';
}
$qa_content['a_list']['title'] = $split['prefix'] . $split['data'] . $split['suffix'];
} else
$qa_content['a_list']['title_tags'] .= ' style="display:none;" ';
}
if (!$formrequested)
if (!$formrequested) {
$qa_content['page_links'] = qa_html_page_links(qa_request(), $pagestart, $pagesize, $countforpages, qa_opt('pages_prev_next'), array(), false, 'a_list_title');
}
// Some generally useful stuff
if (qa_using_categories() && count($categories))
if (qa_using_categories() && count($categories)) {
$qa_content['navigation']['cat'] = qa_category_navigation($categories, $question['categoryid']);
}
if (isset($jumptoanchor))
if (isset($jumptoanchor)) {
$qa_content['script_onloads'][] = array(
'qa_scroll_page_to($("#"+' . qa_js($jumptoanchor) . ').offset().top);'
);
}
// Determine whether this request should be counted for page view statistics.
......
......@@ -810,6 +810,7 @@ function qa_suspend_update_counts($suspend = true)
/**
* Returns whether counts should currently be updated (i.e. if count updating has not been suspended).
* @return bool
*/
function qa_should_update_counts()
{
......
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