Skip to content

Commit

Permalink
Var selectcomm_backup_prob, allow Slash.pm selectComments to have a
Browse files Browse the repository at this point in the history
probability of hitting the backup DB.  Also internal use_writer flag
renamed to more descriptive force_read_from_master.
  • Loading branch information
jamiemccarthy committed Jan 31, 2003
1 parent bdae0c4 commit dcbf48f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
20 changes: 12 additions & 8 deletions Slash/Slash.pm
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions sql/mysql/defaults.sql
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions sql/mysql/upgrades
Expand Up @@ -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');

6 changes: 4 additions & 2 deletions themes/slashcode/htdocs/comments.pl
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit dcbf48f

Please sign in to comment.