]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 403824: Replace table locks in most Bugzilla files with transactions - Patch...
authorlpsolit%gmail.com <>
Thu, 15 Nov 2007 04:56:31 +0000 (04:56 +0000)
committerlpsolit%gmail.com <>
Thu, 15 Nov 2007 04:56:31 +0000 (04:56 +0000)
attachment.cgi
contrib/merge-users.pl
query.cgi
userprefs.cgi
votes.cgi

index 2d5b6abc49ef049e8b55c1d13f288ecb3d5cda04..23841571c7da8b27aeb9a62e75d8e4b352bd5a34 100755 (executable)
@@ -479,18 +479,8 @@ sub update {
     });
     Bugzilla::Flag::validate($cgi, $bug->id, $attachment->id);
 
-    # Lock database tables in preparation for updating the attachment.
-    $dbh->bz_lock_tables('attachments WRITE', 'flags WRITE' ,
-          'flagtypes READ', 'fielddefs READ', 'bugs_activity WRITE',
-          'flaginclusions AS i READ', 'flagexclusions AS e READ',
-          # cc, bug_group_map, user_group_map, and groups are in here so we
-          # can check the permissions of flag requestees and email addresses
-          # on the flag type cc: lists via the CanSeeBug
-          # function call in Flag::notify. group_group_map is in here si
-          # Bugzilla::User can flatten groups.
-          'bugs WRITE', 'profiles READ', 'email_setting READ',
-          'cc READ', 'bug_group_map READ', 'user_group_map READ',
-          'group_group_map READ', 'groups READ', 'group_control_map READ');
+    # Start a transaction in preparation for updating the attachment.
+    $dbh->bz_start_transaction();
 
   # Quote the description and content type for use in the SQL UPDATE statement.
   my $description = $cgi->param('description');
@@ -560,8 +550,8 @@ sub update {
                   $attachment->isprivate, $updated_attachment->isprivate);
   }
   
-  # Unlock all database tables now that we are finished updating the database.
-  $dbh->bz_unlock_tables();
+  # Commit the transaction now that we are finished updating the database.
+  $dbh->bz_commit_transaction();
 
   # If the user submitted a comment while editing the attachment,
   # add the comment to the bug.
@@ -634,14 +624,14 @@ sub delete_attachment {
         $template->process("attachment/delete_reason.txt.tmpl", $vars, \$msg)
           || ThrowTemplateError($template->error());
 
-        $dbh->bz_lock_tables('attachments WRITE', 'attach_data WRITE', 'flags WRITE');
+        $dbh->bz_start_transaction();
         $dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $attachment->id);
         $dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isurl = ?,
                          isobsolete = ?
                   WHERE attach_id = ?', undef,
                  ('text/plain', 0, 0, 1, $attachment->id));
         $dbh->do('DELETE FROM flags WHERE attach_id = ?', undef, $attachment->id);
-        $dbh->bz_unlock_tables;
+        $dbh->bz_commit_transaction();
 
         # If the attachment is stored locally, remove it.
         if (-e $attachment->_get_local_filename) {
index ac689abfdf091bd73cb179e30b85c9385f7fdbfd..70250a1eeb1b893803db89a9cb3ccee3c5b2382f 100644 (file)
@@ -154,9 +154,8 @@ my $changes = {
     profiles        => [], # ['userid'],
 };
 
-# Lock tables
-my @locked_tables = map {"$_ WRITE"} keys(%$changes);
-$dbh->bz_lock_tables(@locked_tables);
+# Start the transaction
+$dbh->bz_start_transaction();
 
 # Delete old records from logincookies and tokens tables.
 $dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id);
@@ -230,7 +229,7 @@ print "OK, records in the 'mailto' column of the 'whine_schedules' table\n" .
 # Delete the old record from the profiles table.
 $dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $old_id);
 
-# Unlock tables
-$dbh->bz_unlock_tables();
+# Commit the transaction
+$dbh->bz_commit_transaction();
 
 print "Done.\n";
index aaabc1529493a41bc62326a9c6aad946856e1a63..622c1588cef4b8b6083eb804c1e3c3fe68b4e424 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -70,7 +70,7 @@ if ($userid) {
                 # If the query name contains invalid characters, don't import.
                 $name =~ /[<>&]/ && next;
                 trick_taint($name);
-                $dbh->bz_lock_tables('namedqueries WRITE');
+                $dbh->bz_start_transaction();
                 my $query = $dbh->selectrow_array(
                     "SELECT query FROM namedqueries " .
                      "WHERE userid = ? AND name = ?",
@@ -80,7 +80,7 @@ if ($userid) {
                             "(userid, name, query) VALUES " .
                             "(?, ?, ?)", undef, ($userid, $name, $value));
                 }
-                $dbh->bz_unlock_tables();
+                $dbh->bz_commit_transaction();
             }
             $cgi->remove_cookie($cookiename);
         }
index e2cc2e0ce9f2dceab80951a49c6b258f72d92b97..57cbd4c211e7f716bb9db48579243f2715dc7eea 100755 (executable)
@@ -255,7 +255,7 @@ sub SaveEmail {
     ###########################################################################
     # Role-based preferences
     ###########################################################################
-    $dbh->bz_lock_tables("email_setting WRITE");
+    $dbh->bz_start_transaction();
 
     # Delete all the user's current preferences
     $dbh->do("DELETE FROM email_setting WHERE user_id = ?", undef, $user->id);
@@ -302,7 +302,7 @@ sub SaveEmail {
         }
     }
 
-    $dbh->bz_unlock_tables();
+    $dbh->bz_commit_transaction();
 
     ###########################################################################
     # User watching
@@ -311,11 +311,7 @@ sub SaveEmail {
         && (defined $cgi->param('new_watchedusers')
             || defined $cgi->param('remove_watched_users'))) 
     {
-        # Just in case.  Note that this much locking is actually overkill:
-        # we don't really care if anyone reads the watch table.  So 
-        # some small amount of contention could be gotten rid of by
-        # using user-defined locks rather than table locking.
-        $dbh->bz_lock_tables('watch WRITE', 'profiles READ');
+        $dbh->bz_start_transaction();
 
         # Use this to protect error messages on duplicate submissions
         my $old_watch_ids =
@@ -356,7 +352,7 @@ sub SaveEmail {
             }
         }
 
-        $dbh->bz_unlock_tables();
+        $dbh->bz_commit_transaction();
     }
 }
 
index 9fe94484a16ecdad72a1d5d8455a3b9a39841ac7..4b26229a5b2c69e5430c09b3f020224fbb646a1c 100755 (executable)
--- a/votes.cgi
+++ b/votes.cgi
@@ -130,9 +130,7 @@ sub show_user {
 
     my $canedit = (Bugzilla->params->{'usevotes'} && $userid == $who) ? 1 : 0;
 
-    $dbh->bz_lock_tables('bugs READ', 'products READ', 'votes WRITE',
-             'cc READ', 'bug_group_map READ', 'user_group_map READ',
-             'group_group_map READ', 'groups READ', 'group_control_map READ');
+    $dbh->bz_start_transaction();
 
     if ($canedit && $bug_id) {
         # Make sure there is an entry for this bug
@@ -197,7 +195,7 @@ sub show_user {
     }
 
     $dbh->do('DELETE FROM votes WHERE vote_count <= 0');
-    $dbh->bz_unlock_tables();
+    $dbh->bz_commit_transaction();
 
     $vars->{'canedit'} = $canedit;
     $vars->{'voting_user'} = { "login" => $name };