Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion qa-include/app/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function qa_default_option($name)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }

require_once QA_INCLUDE_DIR . 'db/hotness.php';

$fixed_defaults = array(
'allow_anonymous_naming' => 1,
'allow_change_usernames' => 1,
Expand Down Expand Up @@ -353,7 +355,7 @@ function qa_default_option($name)
'points_q_voted_max_loss' => 3,
'points_select_a' => 3,
'q_urls_title_length' => 50,
'recalc_hotness_q_view' => 1,
'recalc_hotness_frequency' => QA_HOTNESS_RECALC_ALWAYS,
'show_a_c_links' => 1,
'show_a_form_immediate' => 'if_no_as',
'show_c_reply_buttons' => 1,
Expand Down
6 changes: 4 additions & 2 deletions qa-include/app/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ function qa_do_content_stats($qa_content)

$viewsIncremented = qa_db_increment_views($qa_content['inc_views_postid']);

if ($viewsIncremented && qa_opt('recalc_hotness_q_view')) {
if ($viewsIncremented && (int)qa_opt('recalc_hotness_frequency') === QA_HOTNESS_RECALC_ALWAYS) {
qa_db_hotness_update($qa_content['inc_views_postid']);
}

Expand Down Expand Up @@ -470,6 +470,8 @@ function qa_content_prepare($voting = false, $categoryids = array())

global $qa_template, $qa_page_error_html;

require_once QA_INCLUDE_DIR . 'db/hotness.php';

if (QA_DEBUG_PERFORMANCE) {
global $qa_usage;
$qa_usage->mark('control');
Expand Down Expand Up @@ -579,7 +581,7 @@ function qa_content_prepare($voting = false, $categoryids = array())
);
}

if (qa_opt('nav_hot')) {
if (qa_opt('nav_hot') && (int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
$qa_content['navigation']['main']['hot'] = array(
'url' => qa_path_html('hot'),
'label' => qa_lang_html('main/nav_hot'),
Expand Down
11 changes: 9 additions & 2 deletions qa-include/app/post-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function qa_question_create($followanswer, $userid, $handle, $cookieid, $title,
$categoryid = null, $extravalue = null, $queued = false, $name = null)
{
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'db/hotness.php';

$postid = qa_db_post_create($queued ? 'Q_QUEUED' : 'Q', @$followanswer['postid'], $userid, isset($userid) ? null : $cookieid,
qa_remote_ip_address(), $title, $content, $format, $tagstring, qa_combine_notify_email($userid, $notify, $email),
Expand All @@ -80,7 +81,9 @@ function qa_question_create($followanswer, $userid, $handle, $cookieid, $title,
}

qa_db_posts_calc_category_path($postid);
qa_db_hotness_update($postid);
if ((int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
qa_db_hotness_update($postid);
}

if ($queued) {
qa_db_queuedcount_update();
Expand Down Expand Up @@ -248,8 +251,12 @@ function qa_answer_create($userid, $handle, $cookieid, $content, $format, $text,
*/
function qa_update_q_counts_for_a($questionid)
{
require_once QA_INCLUDE_DIR . 'db/hotness.php';

qa_db_post_acount_update($questionid);
qa_db_hotness_update($questionid);
if ((int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
qa_db_hotness_update($questionid);
}
qa_db_acount_update();
qa_db_unaqcount_update();
qa_db_unupaqcount_update();
Expand Down
7 changes: 6 additions & 1 deletion qa-include/app/post-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,12 @@ function qa_question_set_status($oldquestion, $status, $userid, $handle, $cookie

else { // ... otherwise we're approving original created post
qa_db_post_set_created($oldquestion['postid'], null);
qa_db_hotness_update($oldquestion['postid']);

require_once QA_INCLUDE_DIR . 'db/hotness.php';

if ((int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
qa_db_hotness_update($oldquestion['postid']);
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions qa-include/app/posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,16 @@ function qa_post_set_status($postid, $status, $byuserid = null)
*/
function qa_post_set_created($postid, $created)
{
$oldpost = qa_post_get_full($postid);

qa_db_post_set_created($postid, $created);

require_once QA_INCLUDE_DIR . 'db/hotness.php';

if ((int)qa_opt('recalc_hotness_frequency') === QA_HOTNESS_RECALC_NEVER) {
return;
}

$oldpost = qa_post_get_full($postid);

switch ($oldpost['basetype']) {
case 'Q':
qa_db_hotness_update($postid);
Expand Down
18 changes: 11 additions & 7 deletions qa-include/app/q-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl
*/
function qa_qs_sub_navigation($sort, $categoryslugs)
{
require_once QA_INCLUDE_DIR . 'db/hotness.php';

$request = 'questions';

if (isset($categoryslugs)) {
Expand All @@ -167,17 +169,19 @@ function qa_qs_sub_navigation($sort, $categoryslugs)
}
}

$navigation = array(
'recent' => array(
'label' => qa_lang('main/nav_most_recent'),
'url' => qa_path_html($request),
),
$navigation['recent'] = array(
'label' => qa_lang('main/nav_most_recent'),
'url' => qa_path_html($request),
);

'hot' => array(
if ((int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
$navigation['hot'] = array(
'label' => qa_lang('main/nav_hot'),
'url' => qa_path_html($request, array('sort' => 'hot')),
),
);
}

$navigation += array(
'votes' => array(
'label' => qa_lang('main/nav_most_votes'),
'url' => qa_path_html($request, array('sort' => 'votes')),
Expand Down
2 changes: 1 addition & 1 deletion qa-include/app/votes.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function qa_vote_set($post, $userid, $handle, $cookieid, $vote)

qa_db_points_update_ifuser($post['userid'], array($prefix . 'voteds', 'upvoteds', 'downvoteds'));

if ($prefix === 'q') {
if ($prefix === 'q' && (int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
qa_db_hotness_update($post['postid']);
}

Expand Down
5 changes: 5 additions & 0 deletions qa-include/db/hotness.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
}


define('QA_HOTNESS_RECALC_NEVER', 0);
define('QA_HOTNESS_RECALC_NO_Q_VIEW', 1);
define('QA_HOTNESS_RECALC_ALWAYS', 2);


/**
* Increment the views counter for the post (if different IP from last view).
* @param int $postid The ID of the post
Expand Down
10 changes: 8 additions & 2 deletions qa-include/db/recalc.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,16 @@ function qa_db_posts_get_for_recounting($startpostid, $count)
*/
function qa_db_posts_votes_recount($firstpostid, $lastpostid)
{
require_once QA_INCLUDE_DIR . 'db/hotness.php';

qa_db_query_sub(
'UPDATE ^posts AS x, (SELECT ^posts.postid, COALESCE(SUM(GREATEST(0,^uservotes.vote)),0) AS upvotes, -COALESCE(SUM(LEAST(0,^uservotes.vote)),0) AS downvotes, COALESCE(SUM(IF(^uservotes.flag, 1, 0)),0) AS flagcount FROM ^posts LEFT JOIN ^uservotes ON ^uservotes.postid=^posts.postid WHERE ^posts.postid>=# AND ^posts.postid<=# GROUP BY postid) AS a SET x.upvotes=a.upvotes, x.downvotes=a.downvotes, x.netvotes=a.upvotes-a.downvotes, x.flagcount=a.flagcount WHERE x.postid=a.postid',
$firstpostid, $lastpostid
);

qa_db_hotness_update($firstpostid, $lastpostid);
if ((int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
qa_db_hotness_update($firstpostid, $lastpostid);
}
}


Expand All @@ -236,7 +240,9 @@ function qa_db_posts_answers_recount($firstpostid, $lastpostid)
$firstpostid, $lastpostid
);

qa_db_hotness_update($firstpostid, $lastpostid);
if ((int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
qa_db_hotness_update($firstpostid, $lastpostid);
}
}


Expand Down
5 changes: 4 additions & 1 deletion qa-include/lang/qa-lang-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@
'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' => 'May slightly improve page speed if disabled, but hotness values will become out of date if views are included in hotness 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', // @deprecated
'recalc_hotness_never_note' => 'Hotness is never recalculated or even used. Removes the hotness submenu in questions list. No performance impact.',
'recalc_hotness_no_q_view_note' => 'Hotness is recalculated in several events (e.g. post creation) with the exception of question views. Medium performance impact.',
'recalc_hotness_always_note' => 'Hotness is recalculated in all possible events, including question views. High performance impact.',
'recalc_points' => 'Recalculate user points',
'recalc_points_complete' => 'All user points were successfully recalculated.',
'recalc_points_note' => ' - for user ranking and points displays',
Expand Down
6 changes: 5 additions & 1 deletion qa-include/lang/qa-lang-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@
'points_vote_up_q' => 'Voting up a question:',
'q_urls_remove_accents' => 'Remove accents from question URLs:',
'q_urls_title_length' => 'Question title length in URLs:',
'recalc_hotness_q_view' => 'Recalculate hotness on every question page view:',
'recalc_hotness_always' => 'Always recalculate, including page views',
'recalc_hotness_frequency' => 'Hotness recalculation frequency:',
'recalc_hotness_never' => 'Never recalculate',
'recalc_hotness_no_q_view' => 'Always recalculate, except for page views',
'recalc_hotness_q_view' => 'Recalculate hotness on every question page view:', // @deprecated
'register_notify_admin' => 'Email me when a new user registers:',
'search_module' => 'Use search module:',
'show_a_form_immediate' => 'Show answer form immediately:',
Expand Down
19 changes: 14 additions & 5 deletions qa-include/pages/admin/admin-default.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}

require_once QA_INCLUDE_DIR . 'db/admin.php';
require_once QA_INCLUDE_DIR . 'db/hotness.php';
require_once QA_INCLUDE_DIR . 'db/maxima.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/options.php';
Expand Down Expand Up @@ -193,7 +194,6 @@
'notify_admin_q_post' => 'checkbox',
'notify_users_default' => 'checkbox',
'q_urls_remove_accents' => 'checkbox',
'recalc_hotness_q_view' => 'checkbox',
'register_notify_admin' => 'checkbox',
'show_c_reply_buttons' => 'checkbox',
'show_compact_numbers' => 'checkbox',
Expand Down Expand Up @@ -388,7 +388,7 @@
case 'viewing':
$subtitle = 'admin/viewing_title';
$showoptions = array(
'q_urls_title_length', 'q_urls_remove_accents', 'do_count_q_views', 'show_view_counts', 'show_view_count_q_page', 'recalc_hotness_q_view', '',
'q_urls_title_length', 'q_urls_remove_accents', 'do_count_q_views', 'show_view_counts', 'show_view_count_q_page', 'recalc_hotness_frequency', '',
'voting_on_qs', 'voting_on_q_page_only', 'voting_on_as', 'voting_on_cs', 'votes_separated', '',
'show_url_links', 'links_in_new_window', 'show_when_created', 'show_full_date_days'
);
Expand Down Expand Up @@ -424,7 +424,6 @@
$checkboxtodisplay = array(
'show_view_counts' => 'option_do_count_q_views',
'show_view_count_q_page' => 'option_do_count_q_views',
'recalc_hotness_q_view' => 'option_do_count_q_views',
'votes_separated' => 'option_voting_on_qs || option_voting_on_as',
'voting_on_q_page_only' => 'option_voting_on_qs',
'show_full_date_days' => 'option_show_when_created',
Expand Down Expand Up @@ -1204,8 +1203,18 @@ function qa_optionfield_make_select(&$optionfield, $options, $value, $default)
$optionfield['note'] = qa_lang_html('admin/characters');
break;

case 'recalc_hotness_q_view':
$optionfield['note'] = '<span class="qa-form-wide-help" title="' . qa_lang_html('admin/recalc_hotness_q_view_note') . '">?</span>';
case 'recalc_hotness_frequency':
$hotnessOptions = array(
QA_HOTNESS_RECALC_NEVER => 'recalc_hotness_never',
QA_HOTNESS_RECALC_NO_Q_VIEW => 'recalc_hotness_no_q_view',
QA_HOTNESS_RECALC_ALWAYS => 'recalc_hotness_always',
);

qa_optionfield_make_select($optionfield, array_map(function ($optionValue) {
return qa_lang_html('options/' . $optionValue);
}, $hotnessOptions), $value, QA_HOTNESS_RECALC_ALWAYS);
// recalc_hotness_always_note, recalc_hotness_no_q_view_note, recalc_hotness_never_note
$optionfield['note'] = sprintf('<span class="qa-form-wide-help" title="%s">?</span>', qa_lang_html(sprintf('admin/%s_note', isset($hotnessOptions[$value]) ? $hotnessOptions[$value] : reset($hotnessOptions))));
break;

case 'min_num_q_tags':
Expand Down
24 changes: 17 additions & 7 deletions qa-include/pages/admin/admin-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

require_once QA_INCLUDE_DIR . 'app/admin.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'db/hotness.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';


Expand Down Expand Up @@ -63,12 +64,6 @@
'nav_activity' => 'main/nav_activity',
$hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home' => $hascustomhome ? 'main/nav_qa' : 'admin/nav_qa_is_home',
'nav_questions' => 'main/nav_qs',
'nav_hot' => 'main/nav_hot',
'nav_unanswered' => 'main/nav_unanswered',
'nav_tags' => 'main/nav_tags',
'nav_categories' => 'main/nav_categories',
'nav_users' => 'main/nav_users',
'nav_ask' => 'main/nav_ask',
);

$navpaths = array(
Expand All @@ -77,7 +72,22 @@
'nav_qa_not_home' => 'qa',
'nav_qa_is_home' => '',
'nav_questions' => 'questions',
'nav_hot' => 'hot',
);

if ((int)qa_opt('recalc_hotness_frequency') > QA_HOTNESS_RECALC_NEVER) {
$navoptions['nav_hot'] = 'main/nav_hot';
$navpaths['nav_hot'] = 'hot';
}

$navoptions += array(
'nav_unanswered' => 'main/nav_unanswered',
'nav_tags' => 'main/nav_tags',
'nav_categories' => 'main/nav_categories',
'nav_users' => 'main/nav_users',
'nav_ask' => 'main/nav_ask',
);

$navpaths += array(
'nav_unanswered' => 'unanswered',
'nav_tags' => 'tags',
'nav_categories' => 'categories',
Expand Down