From: Aaron Schulz Date: Fri, 19 Aug 2016 18:31:41 +0000 (-0700) Subject: Avoid INSERT..SELECT in MovePage X-Git-Tag: 1.31.0-rc.0~5966^2 X-Git-Url: http://git.cyclocoop.org///%22%40url%40//%22?a=commitdiff_plain;h=7cd8913897761f06c5aca1e9eedb6844355c934b;p=lhc%2Fweb%2Fwiklou.git Avoid INSERT..SELECT in MovePage That construct has poor locking characteristics in terms of auto-inc columns as well as not allowing such inserts concurrently for statement-based replication. Also, the INSERT..SELECT did not have an ORDER BY, which could lead to pr_id drift with statement based replication. Change-Id: I47ca89abcbe4598d3b56cf077a47055500a0647f --- diff --git a/includes/MovePage.php b/includes/MovePage.php index bc3305ab04..d17f23422d 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -297,19 +297,25 @@ class MovePage { if ( $protected ) { # Protect the redirect title as the title used to be... - $dbw->insertSelect( 'page_restrictions', 'page_restrictions', - [ - 'pr_page' => $redirid, - 'pr_type' => 'pr_type', - 'pr_level' => 'pr_level', - 'pr_cascade' => 'pr_cascade', - 'pr_user' => 'pr_user', - 'pr_expiry' => 'pr_expiry' - ], + $res = $dbw->select( + 'page_restrictions', + '*', [ 'pr_page' => $pageid ], __METHOD__, - [ 'IGNORE' ] + 'FOR UPDATE' ); + $rowsInsert = []; + foreach ( $res as $row ) { + $rowsInsert[] = [ + 'pr_page' => $redirid, + 'pr_type' => $row->pr_type, + 'pr_level' => $row->pr_level, + 'pr_cascade' => $row->pr_cascade, + 'pr_user' => $row->pr_user, + 'pr_expiry' => $row->pr_expiry + ]; + } + $dbw->insert( 'page_restrictions', $rowsInsert, __METHOD__, [ 'IGNORE' ] ); // Build comment for log $comment = wfMessage(