]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 471880: More scripts should use the shadow DB instead of the master DB - Patch...
authorlpsolit%gmail.com <>
Sun, 25 Jan 2009 12:42:51 +0000 (12:42 +0000)
committerlpsolit%gmail.com <>
Sun, 25 Jan 2009 12:42:51 +0000 (12:42 +0000)
config.cgi
describecomponents.cgi
describekeywords.cgi
query.cgi
request.cgi
show_activity.cgi
show_bug.cgi

index c229dacd693e44815d44fb2bd4177ae0da3add00..282b959571a32f36caa34fe96d9643ca61721df2 100755 (executable)
@@ -46,6 +46,9 @@ if (Bugzilla->params->{'requirelogin'} && !$user->id) {
     display_data();
 }
 
+# Get data from the shadow DB as they don't change very often.
+Bugzilla->switch_to_shadow_db;
+
 # Pass a bunch of Bugzilla configuration to the templates.
 my $vars = {};
 $vars->{'priority'}  = get_legal_field_values('priority');
index 806183783667bd8b4665cf835645065a7f346702..6d4722ad820acae38a4252ec6873af16e3f04215 100755 (executable)
@@ -32,14 +32,15 @@ use Bugzilla::Error;
 use Bugzilla::Product;
 
 my $user = Bugzilla->login();
-
 my $cgi = Bugzilla->cgi;
-my $dbh = Bugzilla->dbh;
 my $template = Bugzilla->template;
 my $vars = {};
 
 print $cgi->header();
 
+# This script does nothing but displaying mostly static data.
+Bugzilla->switch_to_shadow_db;
+
 my $product_name = trim($cgi->param('product') || '');
 my $product = new Bugzilla::Product({'name' => $product_name});
 
index 5ff5c5089631e98a05423ebed55700f790e1f10a..9796b77d502b9d7460133fe4bcd66902aac172ae 100755 (executable)
@@ -35,6 +35,9 @@ my $cgi = Bugzilla->cgi;
 my $template = Bugzilla->template;
 my $vars = {};
 
+# Run queries against the shadow DB.
+Bugzilla->switch_to_shadow_db;
+
 $vars->{'keywords'} = Bugzilla::Keyword->get_all_with_bug_count();
 $vars->{'caneditkeywords'} = Bugzilla->user->in_group("editkeywords");
 
index f41310bb73d09a6da1962ab1e827467b983298b8..a3e3445b8180bea0cc00f69d7deb9da5e949e221 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -96,6 +96,9 @@ if ($cgi->param('nukedefaultquery')) {
     $buffer = "";
 }
 
+# We are done with changes committed to the DB.
+$dbh = Bugzilla->switch_to_shadow_db;
+
 my $userdefaultquery;
 if ($userid) {
     $userdefaultquery = $dbh->selectrow_array(
index 666b74b17e5106d41d8386d602910c5bfff20d5e..5dfb76ddb975a26525ad4c5899d173d2dbd66aa5 100755 (executable)
@@ -42,6 +42,8 @@ use Bugzilla::Component;
 # Make sure the user is logged in.
 my $user = Bugzilla->login();
 my $cgi = Bugzilla->cgi;
+# Force the script to run against the shadow DB. We already validated credentials.
+Bugzilla->switch_to_shadow_db;
 my $template = Bugzilla->template;
 my $action = $cgi->param('action') || '';
 
@@ -94,7 +96,6 @@ exit;
 
 sub queue {
     my $cgi = Bugzilla->cgi;
-    # There are some user privilege checks to do. We do them against the main DB.
     my $dbh = Bugzilla->dbh;
     my $template = Bugzilla->template;
     my $user = Bugzilla->user;
@@ -164,9 +165,7 @@ sub queue {
     $query .= " AND flags.status = '?' " unless $status;
 
     # The set of criteria by which we filter records to display in the queue.
-    # We now move to the shadow DB to query the DB.
     my @criteria = ();
-    $dbh = Bugzilla->switch_to_shadow_db;
 
     # A list of columns to exclude from the report because the report conditions
     # limit the data being displayed to exact matches for those columns.
@@ -304,9 +303,6 @@ sub queue {
     my $flagtypes = get_flag_types();
     push(@types, @$flagtypes);
 
-    # We move back to the main DB to get the list of products the user can see.
-    $dbh = Bugzilla->switch_to_main_db;
-
     $vars->{'products'} = $user->get_selectable_products;
     $vars->{'excluded_columns'} = \@excluded_columns;
     $vars->{'group_field'} = $form_group;
index f7db3dd0b79f0c259f60dea1ecc95dc08e2a1315..27096018fcdbe628c3c61e99200cad7f8d439c9e 100755 (executable)
@@ -50,6 +50,10 @@ my $bug = Bugzilla::Bug->check($id);
 # End Data/Security Validation
 ###############################################################################
 
+# Run queries against the shadow DB. In the worst case, new changes are not
+# visible immediately due to replication lag.
+Bugzilla->switch_to_shadow_db;
+
 ($vars->{'operations'}, $vars->{'incomplete_data'}) = 
     Bugzilla::Bug::GetBugActivity($bug->id);
 
index 62575c5ced1af03cf4b250a4284e998b52764f2e..0578733beeaeffe1a4988f89794cdfaf01e28426 100755 (executable)
@@ -55,6 +55,11 @@ my $format = $template->get_format("bug/show", scalar $cgi->param('format'),
 my @bugs = ();
 my %marks;
 
+# If the user isn't logged in, we use data from the shadow DB. If he plans
+# to edit the bug(s), he will have to log in first, meaning that the data
+# will be reloaded anyway, from the main DB.
+Bugzilla->switch_to_shadow_db unless $user->id;
+
 if ($single) {
     my $id = $cgi->param('id');
     push @bugs, Bugzilla::Bug->check($id);