From 7cd8913897761f06c5aca1e9eedb6844355c934b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 19 Aug 2016 11:31:41 -0700 Subject: [PATCH] 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 --- includes/MovePage.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) 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( -- 2.20.1