From: lpsolit%gmail.com <> Date: Mon, 14 Nov 2005 01:50:47 +0000 (+0000) Subject: Bug 313695: buglist.cgi and some other scripts do not use the shadow DB anymore ... X-Git-Tag: bugzilla-2.22rc1~150 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03352ccf9bdb6b816e0650f8f76e008a17df87c0;p=thirdparty%2Fbugzilla.git Bug 313695: buglist.cgi and some other scripts do not use the shadow DB anymore - Patch by Frédéric Buclin r/a=justdave --- diff --git a/Bugzilla.pm b/Bugzilla.pm index de30d8c99b..5012909929 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -242,17 +242,6 @@ sub batch { return $_batch || 0; } -sub dbwritesallowed { - my $class = shift; - - # We can write if we are connected to the main database. - # Note that if we don't have a shadowdb, then we claim that its ok - # to write even if we're nominally connected to the shadowdb. - # This is OK because this method is only used to test if misc - # updates can be done, rather than anything complicated. - return $class->dbh == $_dbh_main; -} - sub switch_to_shadow_db { my $class = shift; @@ -265,12 +254,20 @@ sub switch_to_shadow_db { } $_dbh = $_dbh_shadow; + # we have to return $class->dbh instead of $_dbh as + # $_dbh_shadow may be undefined if no shadow DB is used + # and no connection to the main DB has been established yet. + return $class->dbh; } sub switch_to_main_db { my $class = shift; $_dbh = $_dbh_main; + # We have to return $class->dbh instead of $_dbh as + # $_dbh_main may be undefined if no connection to the main DB + # has been established yet. + return $class->dbh; } # Private methods @@ -440,12 +437,6 @@ Bugzilla->batch will return the current state of this flag. The current database handle. See L. -=item C - -Determines if writes to the database are permitted. This is usually used to -determine if some general cleanup needs to occur (such as clearing the token -table) - =item C Switch from using the main database to using the shadow database. diff --git a/buglist.cgi b/buglist.cgi index f39bb14b80..c46141638e 100755 --- a/buglist.cgi +++ b/buglist.cgi @@ -870,7 +870,7 @@ if ($serverpush) { # Connect to the shadow database if this installation is using one to improve # query performance. -Bugzilla->switch_to_shadow_db(); +$dbh = Bugzilla->switch_to_shadow_db(); # Normally, we ignore SIGTERM and SIGPIPE (see globals.pl) but we need to # respond to them here to prevent someone DOSing us by reloading a query diff --git a/collectstats.pl b/collectstats.pl index a12c85586c..e087c28d04 100755 --- a/collectstats.pl +++ b/collectstats.pl @@ -458,10 +458,8 @@ sub CollectSeriesData { # We save a copy of the main $dbh and then switch to the shadow and get # that one too. Remember, these may be the same. - Bugzilla->switch_to_main_db(); - my $dbh = Bugzilla->dbh; - Bugzilla->switch_to_shadow_db(); - my $shadow_dbh = Bugzilla->dbh; + my $dbh = Bugzilla->switch_to_main_db(); + my $shadow_dbh = Bugzilla->switch_to_shadow_db(); my $serieses = $dbh->selectall_hashref("SELECT series_id, query, creator " . "FROM series " . diff --git a/duplicates.cgi b/duplicates.cgi index 07bddc6881..10ba5bf2b8 100755 --- a/duplicates.cgi +++ b/duplicates.cgi @@ -37,7 +37,6 @@ use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Constants; my $cgi = Bugzilla->cgi; -my $dbh = Bugzilla->dbh; # Go directly to the XUL version of the duplicates report (duplicates.xul) # if the user specified ctype=xul. Adds params if they exist, and directs @@ -66,7 +65,7 @@ else { Bugzilla->login(); } -Bugzilla->switch_to_shadow_db(); +my $dbh = Bugzilla->switch_to_shadow_db(); use vars qw (@legal_product); diff --git a/report.cgi b/report.cgi index 4e21525427..7286c551e6 100755 --- a/report.cgi +++ b/report.cgi @@ -35,7 +35,6 @@ my $cgi = Bugzilla->cgi; my $template = Bugzilla->template; my $vars = {}; my $buffer = $cgi->query_string(); -my $dbh = Bugzilla->dbh; # Go straight back to query.cgi if we are adding a boolean chart. if (grep(/^cmd-/, $cgi->param())) { @@ -53,7 +52,7 @@ GetVersionTable(); Bugzilla->login(LOGIN_REQUIRED); -Bugzilla->switch_to_shadow_db(); +my $dbh = Bugzilla->switch_to_shadow_db(); my $action = $cgi->param('action') || 'menu'; diff --git a/showdependencygraph.cgi b/showdependencygraph.cgi index 0bdaab3e65..8f94aa918a 100755 --- a/showdependencygraph.cgi +++ b/showdependencygraph.cgi @@ -36,13 +36,11 @@ require "globals.pl"; Bugzilla->login(); my $cgi = Bugzilla->cgi; -my $dbh = Bugzilla->dbh; my $template = Bugzilla->template; my $vars = {}; - # Connect to the shadow database if this installation is using one to improve # performance. -Bugzilla->switch_to_shadow_db(); +my $dbh = Bugzilla->switch_to_shadow_db(); my %seen; my %edgesdone; diff --git a/showdependencytree.cgi b/showdependencytree.cgi index 3e4c4bf883..d9d71b0abc 100755 --- a/showdependencytree.cgi +++ b/showdependencytree.cgi @@ -33,13 +33,11 @@ use Bugzilla::Bug; Bugzilla->login(); my $cgi = Bugzilla->cgi; -my $dbh = Bugzilla->dbh; my $template = Bugzilla->template; my $vars = {}; - # Connect to the shadow database if this installation is using one to improve # performance. -Bugzilla->switch_to_shadow_db(); +my $dbh = Bugzilla->switch_to_shadow_db(); ################################################################################ # Data/Security Validation # diff --git a/whine.pl b/whine.pl index 52e5840119..0c8815368e 100755 --- a/whine.pl +++ b/whine.pl @@ -323,7 +323,7 @@ while (my $event = get_next_event) { # We loop for each target user because some of the queries will be using # subjective pronouns - Bugzilla->switch_to_shadow_db(); + $dbh = Bugzilla->switch_to_shadow_db(); for my $target (@{$event->{'mailto'}}) { my $args = { 'subject' => $event->{'subject'}, @@ -348,7 +348,7 @@ while (my $event = get_next_event) { mail($args); } - Bugzilla->switch_to_main_db(); + $dbh = Bugzilla->switch_to_main_db(); } ################################################################################