Bug 18651: Limit the life span of the LOCK
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 15 Jun 2017 23:25:18 +0000 (20:25 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 20 Jun 2017 17:29:21 +0000 (14:29 -0300)
We only need the table to be locked for the fetch, increment, store sequence

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
C4/Circulation.pm

index 60c29a9..c89624e 100644 (file)
@@ -2175,11 +2175,11 @@ sub MarkIssueReturned {
     my $do_not_lock = ( exists $ENV{_} && $ENV{_} =~ m|prove| ) || $ENV{KOHA_NO_TABLE_LOCKS};
     $schema->txn_do(sub {
 
+        $dbh->do( $query, undef, @bind );
+
         C4::Context->dbh->do(q|LOCK TABLE old_issues READ|) unless $do_not_lock;
         C4::Context->dbh->do(q|LOCK TABLE old_issues WRITE|) unless $do_not_lock;
 
-        $dbh->do( $query, undef, @bind );
-
         my $original_issue_id = $issue_id;
         my $issue = Koha::Checkouts->find( $issue_id ); # FIXME should be fetched earlier
 
@@ -2196,6 +2196,8 @@ sub MarkIssueReturned {
         $old_checkout_data->{issue_id} = $issue_id;
         my $old_checkout = Koha::Old::Checkout->new($old_checkout_data)->store;
 
+        C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock;
+
         # Update the fines
         $dbh->do(q|UPDATE accountlines SET issue_id = ? WHERE issue_id = ?|, undef, $old_checkout->issue_id, $issue->issue_id);
 
@@ -2214,8 +2216,6 @@ sub MarkIssueReturned {
             my $patron = Koha::Patrons->find( $borrowernumber );
             $item->last_returned_by( $patron );
         }
-
-        C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock;
     });
 
     return $issue_id;