diff --git a/Slash/Slash.pm b/Slash/Slash.pm index 509cb3826..0cd5f6a08 100644 --- a/Slash/Slash.pm +++ b/Slash/Slash.pm @@ -87,15 +87,17 @@ sub selectComments { $cache_read_only = 1 if timeCalc($header->{ts}, '%s') < time - 3600 * $constants->{comment_cache_max_hours}; - my $thisComment; - if ($options->{use_writer}) { - $thisComment = $slashdb->getCommentsForUser( $header->{id}, $cid, $cache_read_only); - } elsif ($constants->{backup_db_user} && rand(1) < 0.5) { - my $backupdb = getObject('Slash::DB', $constants->{backup_db_user}); - $thisComment = $backupdb->getCommentsForUser( $header->{id}, $cid, $cache_read_only); + my $fetchdb; + if (!$options->{force_read_from_master} + && $constants->{backup_db_user} + && $constants->{selectcomm_backup_prob} + && rand(1) < $constants->{selectcomm_backup_prob}) { + $fetchdb = getObject('Slash::DB', $constants->{backup_db_user}); + $fetchdb ||= $slashdb; } else { - $thisComment = $slashdb->getCommentsForUser( $header->{id}, $cid, $cache_read_only); + $fetchdb = $slashdb; } + my $thisComment = $fetchdb->getCommentsForUser($header->{id}, $cid, $cache_read_only); if (!$thisComment) { _print_cchp($header); @@ -474,7 +476,9 @@ sub printComments { my $lvl = 0; # Get the Comments - my($comments, $count) = selectComments($discussion, $cidorpid, { use_writer => $options->{use_writer}}); + my($comments, $count) = selectComments($discussion, $cidorpid, + { force_read_from_master => $options->{force_read_from_master} } + ); if ($cidorpid && !exists($comments->{$cidorpid})) { # No such comment in this discussion. diff --git a/sql/mysql/defaults.sql b/sql/mysql/defaults.sql index 582a8fba3..d27f7340b 100644 --- a/sql/mysql/defaults.sql +++ b/sql/mysql/defaults.sql @@ -816,6 +816,7 @@ INSERT INTO vars (name, value, description) VALUES ('runtask_verbosity','3','How INSERT INTO vars (name, value, description) VALUES ('sbindir','/usr/local/slash/sbin','Where are the sbin scripts kept'); INSERT INTO vars (name, value, description) VALUES ('search_google','0','Turn on to disable local search (and invite users to use google.com)'); INSERT INTO vars (name, value, description) VALUES ('section','index','This is the current setting for section.'); +INSERT INTO vars (name, value, description) VALUES ('selectcomm_backup_prob','0','Probability that Slash.pm selectComments will look to backup_db_user instead of the main db: 0=never, 1=always'); INSERT INTO vars (name, value, description) VALUES ('send_mail','1','Turn On/Off to allow the system to send email messages.'); INSERT INTO vars (name, value, description) VALUES ('siteadmin','admin','The admin for the site'); INSERT INTO vars (name, value, description) VALUES ('siteadmin_name','Slash Admin','The pretty name for the admin for the site'); diff --git a/sql/mysql/upgrades b/sql/mysql/upgrades index 3d3af25df..b21fee897 100644 --- a/sql/mysql/upgrades +++ b/sql/mysql/upgrades @@ -1214,4 +1214,5 @@ ALTER TABLE accesslog ADD secure TINYINT DEFAULT 0 NOT NULL; INSERT INTO vars (name, value, description) VALUES ('accesslog_insert_cachesize','0','Cache accesslog inserts and do this many all at once (0 to disable, if enabled, suggest value of 5 or so)'); INSERT INTO vars (name, value, description) VALUES ('index_gse_backup_prob','0','Probability that index.pl getStoriesEssentials will look to backup_db_user instead of the main db: 0=never, 1=always'); +INSERT INTO vars (name, value, description) VALUES ('selectcomm_backup_prob','0','Probability that Slash.pm selectComments will look to backup_db_user instead of the main db: 0=never, 1=always'); diff --git a/themes/slashcode/htdocs/comments.pl b/themes/slashcode/htdocs/comments.pl index 3b1a49426..0bb138a82 100755 --- a/themes/slashcode/htdocs/comments.pl +++ b/themes/slashcode/htdocs/comments.pl @@ -1112,7 +1112,7 @@ sub submitComment { subnetid => $user->{subnetid}, uid => $form->{postanon} ? $constants->{anonymous_coward_uid} : $user->{uid}, points => $pts, - karma_bonus => $karma_bonus ? 'yes' : 'no', + karma_bonus => $karma_bonus ? 'yes' : 'no', }; my $maxCid = $slashdb->createComment($clean_comment); @@ -1139,7 +1139,9 @@ sub submitComment { } else { slashDisplay('comment_submit') if ! $form->{newdiscussion}; undoModeration($id); - printComments($discussion, $maxCid, $maxCid, { use_writer => 1}) if ! $form->{newdiscussion}; + printComments($discussion, $maxCid, $maxCid, + { force_read_from_master => 1} + ) if !$form->{newdiscussion}; my $tc = $slashdb->getVar('totalComments', 'value', 1); $slashdb->setVar('totalComments', ++$tc);