From 9d6205cdb651fe3769ac58f03068dedb68e7689a Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Mon, 19 Nov 2007 02:20:53 +0000 Subject: Bug 399163: Bugzilla/*.pm should use transactions for database interaction - Patch by Emmanuel Seyman r/a=mkanat --- Bugzilla/Bug.pm | 12 ++++-------- Bugzilla/Install/DB.pm | 12 ++++++------ Bugzilla/Search/Saved.pm | 5 ++--- Bugzilla/Series.pm | 4 ++-- Bugzilla/Token.pm | 8 ++------ Bugzilla/User.pm | 6 ++---- 6 files changed, 18 insertions(+), 29 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index e79a7a1ca..eaf6a9a83 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -738,12 +738,7 @@ sub remove_from_db { # Also, the attach_data table uses attachments.attach_id as a foreign # key, and so indirectly depends on a bug deletion too. - $dbh->bz_lock_tables('attachments WRITE', 'bug_group_map WRITE', - 'bugs WRITE', 'bugs_activity WRITE', 'cc WRITE', - 'dependencies WRITE', 'duplicates WRITE', - 'flags WRITE', 'keywords WRITE', - 'longdescs WRITE', 'votes WRITE', - 'attach_data WRITE'); + $dbh->bz_start_transaction(); $dbh->do("DELETE FROM bug_group_map WHERE bug_id = ?", undef, $bug_id); $dbh->do("DELETE FROM bugs_activity WHERE bug_id = ?", undef, $bug_id); @@ -754,7 +749,6 @@ sub remove_from_db { undef, ($bug_id, $bug_id)); $dbh->do("DELETE FROM flags WHERE bug_id = ?", undef, $bug_id); $dbh->do("DELETE FROM keywords WHERE bug_id = ?", undef, $bug_id); - $dbh->do("DELETE FROM longdescs WHERE bug_id = ?", undef, $bug_id); $dbh->do("DELETE FROM votes WHERE bug_id = ?", undef, $bug_id); # The attach_data table doesn't depend on bugs.bug_id directly. @@ -771,7 +765,9 @@ sub remove_from_db { $dbh->do("DELETE FROM attachments WHERE bug_id = ?", undef, $bug_id); $dbh->do("DELETE FROM bugs WHERE bug_id = ?", undef, $bug_id); - $dbh->bz_unlock_tables(); + $dbh->bz_commit_transaction(); + + $dbh->do("DELETE FROM longdescs WHERE bug_id = ?", undef, $bug_id); # Now this bug no longer exists $self->DESTROY; diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 327487cd9..9934e058f 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -659,8 +659,9 @@ sub _populate_longdescs { " for each 50.\n\n"; local $| = 1; - $dbh->bz_lock_tables('bugs write', 'longdescs write', 'profiles write', - 'bz_schema WRITE'); + # On MySQL, longdescs doesn't benefit from transactions, but this + # doesn't hurt. + $dbh->bz_start_transaction(); $dbh->do('DELETE FROM longdescs'); @@ -722,7 +723,7 @@ sub _populate_longdescs { print "\n\n"; $dbh->bz_drop_column('bugs', 'long_desc'); - $dbh->bz_unlock_tables(); + $dbh->bz_commit_transaction(); } # main if } @@ -740,8 +741,7 @@ sub _update_bugs_activity_field_to_fieldid { [qw(fieldid)]); print "Populating new bugs_activity.fieldid field...\n"; - $dbh->bz_lock_tables('bugs_activity WRITE', 'fielddefs WRITE'); - + $dbh->bz_start_transaction(); my $ids = $dbh->selectall_arrayref( 'SELECT DISTINCT fielddefs.id, bugs_activity.field @@ -760,7 +760,7 @@ sub _update_bugs_activity_field_to_fieldid { $dbh->do("UPDATE bugs_activity SET fieldid = ? WHERE field = ?", undef, $id, $field); } - $dbh->bz_unlock_tables(); + $dbh->bz_commit_transaction(); $dbh->bz_drop_column('bugs_activity', 'field'); } diff --git a/Bugzilla/Search/Saved.pm b/Bugzilla/Search/Saved.pm index bcc72cffe..3484eb3bc 100644 --- a/Bugzilla/Search/Saved.pm +++ b/Bugzilla/Search/Saved.pm @@ -97,13 +97,12 @@ sub create { Bugzilla->login(LOGIN_REQUIRED); my $dbh = Bugzilla->dbh; $class->check_required_create_fields(@_); + $dbh->bz_start_transaction(); my $params = $class->run_create_validators(@_); # Right now you can only create a Saved Search for the current user. $params->{userid} = Bugzilla->user->id; - $dbh->bz_lock_tables('namedqueries WRITE', - 'namedqueries_link_in_footer WRITE'); my $lif = delete $params->{link_in_footer}; my $obj = $class->insert_create_data($params); if ($lif) { @@ -111,7 +110,7 @@ sub create { (user_id, namedquery_id) VALUES (?,?)', undef, $params->{userid}, $obj->id); } - $dbh->bz_unlock_tables(); + $dbh->bz_commit_transaction(); return $obj; } diff --git a/Bugzilla/Series.pm b/Bugzilla/Series.pm index d6fd7a08a..a99c442fe 100644 --- a/Bugzilla/Series.pm +++ b/Bugzilla/Series.pm @@ -170,7 +170,7 @@ sub writeToDatabase { my $self = shift; my $dbh = Bugzilla->dbh; - $dbh->bz_lock_tables('series_categories WRITE', 'series WRITE'); + $dbh->bz_start_transaction(); my $category_id = getCategoryID($self->{'category'}); my $subcategory_id = getCategoryID($self->{'subcategory'}); @@ -209,7 +209,7 @@ sub writeToDatabase { || ThrowCodeError("missing_series_id", { 'series' => $self }); } - $dbh->bz_unlock_tables(); + $dbh->bz_commit_transaction(); } # Check whether a series with this name, category and subcategory exists in diff --git a/Bugzilla/Token.pm b/Bugzilla/Token.pm index 7db6b9165..2f911fca1 100644 --- a/Bugzilla/Token.pm +++ b/Bugzilla/Token.pm @@ -171,12 +171,10 @@ sub issue_session_token { sub CleanTokenTable { my $dbh = Bugzilla->dbh; - $dbh->bz_lock_tables('tokens WRITE'); $dbh->do('DELETE FROM tokens WHERE ' . $dbh->sql_to_days('NOW()') . ' - ' . $dbh->sql_to_days('issuedate') . ' >= ?', undef, MAX_TOKEN_AGE); - $dbh->bz_unlock_tables(); } sub GenerateUniqueToken { @@ -301,9 +299,7 @@ sub delete_token { return unless defined $token; trick_taint($token); - $dbh->bz_lock_tables('tokens WRITE'); $dbh->do("DELETE FROM tokens WHERE token = ?", undef, $token); - $dbh->bz_unlock_tables(); } # Given a token, makes sure it comes from the currently logged in user @@ -364,14 +360,14 @@ sub _create_token { trick_taint($tokentype); trick_taint($eventdata); - $dbh->bz_lock_tables('tokens WRITE'); + $dbh->bz_start_transaction(); my $token = GenerateUniqueToken(); $dbh->do("INSERT INTO tokens (userid, issuedate, token, tokentype, eventdata) VALUES (?, NOW(), ?, ?, ?)", undef, ($userid, $token, $tokentype, $eventdata)); - $dbh->bz_unlock_tables(); + $dbh->bz_commit_transaction(); if (wantarray) { my (undef, $token_ts, undef) = GetTokenData($token); diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 7cd1910c4..bd2a65ae0 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -1583,9 +1583,7 @@ sub create { my $class = ref($invocant) || $invocant; my $dbh = Bugzilla->dbh; - $dbh->bz_lock_tables('profiles WRITE', 'profiles_activity WRITE', - 'user_group_map WRITE', 'email_setting WRITE', 'groups READ', - 'tokens READ', 'fielddefs READ'); + $dbh->bz_start_transaction(); my $user = $class->SUPER::create(@_); @@ -1622,7 +1620,7 @@ sub create { VALUES (?, ?, NOW(), ?, NOW())', undef, ($user->id, $who, $creation_date_fieldid)); - $dbh->bz_unlock_tables(); + $dbh->bz_commit_transaction(); # Return the newly created user account. return $user; -- cgit v1.2.3-24-g4f1b