jenkins-bot has submitted this change and it was merged. Change subject: Combine text and ID update fields ......................................................................
Combine text and ID update fields bumped to version 1.8.0 (requires MediaWiki with fixed bug 50078) Reduce the number of expensive database queries performed while merging by combining the updates of text fields with their corresponding ID fields. This fix requires a MediaWiki core after 20130525 with fixed bug 50078 in Database::delete (merged in https://gerrit.wikimedia.org/r/#/c/70423/ ) Bug: 49517 Bug: 49520 Change-Id: Ibb36ef49e99246e502835f51ab6776422b62438d --- M UserMerge.php M UserMerge_body.php 2 files changed, 117 insertions(+), 37 deletions(-) Approvals: Parent5446: Looks good to me, approved Wikinaut: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/UserMerge.php b/UserMerge.php index ed1a969..cf85115 100644 --- a/UserMerge.php +++ b/UserMerge.php @@ -37,7 +37,7 @@ 'url' => 'https://www.mediawiki.org/wiki/Extension:User_Merge_and_Delete', 'author' => array( 'Tim Laqua', 'Thomas Gries', 'Matthew April' ), 'descriptionmsg' => 'usermerge-desc', - 'version' => '1.7.3' + 'version' => '1.8.0' ); $wgAvailableRights[] = 'usermerge'; diff --git a/UserMerge_body.php b/UserMerge_body.php index 969aa67..d8fc36e 100644 --- a/UserMerge_body.php +++ b/UserMerge_body.php @@ -223,6 +223,83 @@ } /** + * Deduplicate watchlist entries + * which old (merge-from) and new (merge-to) users are watching + * + * @param $oldUser User + * @param $newUser User + * + * @return bool + */ + private function deduplicateWatchlistEntries( $oldUser, $newUser ) { + + $dbw = wfGetDB( DB_MASTER ); + $dbw->begin( __METHOD__ ); + + $res = $dbw->select( + array( + 'w1' => 'watchlist', + 'w2' => 'watchlist' + ), + array( + 'w2.wl_namespace', + 'w2.wl_title' + ), + array( + 'w1.wl_user' => $newUser->getID(), + 'w2.wl_user' => $oldUser->getID() + ), + __METHOD__, + array( 'FOR UPDATE' ), + array( + 'w2' => array( + 'INNER JOIN', + array( + 'w1.wl_namespace = w2.wl_namespace', + 'w1.wl_title = w2.wl_title' + ), + ) + ) + ); + + # Construct an array to delete all watched pages of the old user + # which the new user already watches + $conds = array(); + + foreach ( $res as $result ) { + $conds[] = $dbw->makeList( + array( + 'wl_user' => $oldUser->getID(), + 'wl_namespace' => $result->wl_namespace, + 'wl_title' => $result->wl_title + ), + LIST_AND + ); + } + + if ( empty( $conds ) ) { + $dbw->commit( __METHOD__ ); + return true; + } + + # Perform a multi-row delete + + # requires + # MediaWiki database function with fixed https://bugzilla.wikimedia.org/50078 + # i.e. MediaWiki core after 505dbb331e16a03d87cb4511ee86df12ea295c40 (20130625) + $dbw->delete( + 'watchlist', + $dbw->makeList( $conds, LIST_OR ), + __METHOD__ + ); + + $dbw->commit( __METHOD__ ); + + return true; + } + + + /** * Function to merge database references from one user to another user * * Merges database references from one user ID or username to another user ID or username @@ -238,55 +315,58 @@ * @return bool Always returns true - throws exceptions on failure. */ private function mergeUser( $objNewUser, $newuser_text, $newuserID, $objOldUser, $olduser_text, $olduserID ) { - $idUpdateFields = array( - array( 'archive', 'ar_user' ), - array( 'revision', 'rev_user' ), - array( 'filearchive', 'fa_user' ), - array( 'image', 'img_user' ), - array( 'oldimage', 'oi_user' ), - array( 'recentchanges', 'rc_user' ), + // Fields to update with the format: + // array( tableName, idField, textField ) + $updateFields = array( + array( 'archive', 'ar_user', 'ar_user_text' ), + array( 'revision', 'rev_user', 'rev_user_text' ), + array( 'filearchive', 'fa_user', 'fa_user_text' ), + array( 'image', 'img_user', 'img_user_text' ), + array( 'oldimage', 'oi_user', 'oi_user_text' ), + array( 'recentchanges', 'rc_user', 'rc_user_text' ), array( 'logging', 'log_user' ), - array( 'ipblocks', 'ipb_user' ), - array( 'ipblocks', 'ipb_by' ), + array( 'ipblocks', 'ipb_user', 'ipb_address' ), + array( 'ipblocks', 'ipb_by', 'ipb_by_text' ), array( 'watchlist', 'wl_user' ), - ); - - $textUpdateFields = array( - array( 'archive', 'ar_user_text' ), - array( 'revision', 'rev_user_text' ), - array( 'filearchive', 'fa_user_text' ), - array( 'image', 'img_user_text' ), - array( 'oldimage', 'oi_user_text' ), - array( 'recentchanges', 'rc_user_text' ), - array( 'ipblocks', 'ipb_address' ), - array( 'ipblocks', 'ipb_by_text' ), ); $dbw = wfGetDB( DB_MASTER ); $out = $this->getOutput(); - foreach ( $idUpdateFields as $idUpdateField ) { - $dbw->update( - $idUpdateField[0], - array( $idUpdateField[1] => $newuserID ), - array( $idUpdateField[1] => $olduserID ) - ); - $out->addHTML( - $this->msg( 'usermerge-updating', $idUpdateField[0], $olduserID, $newuserID )->escaped() . - Html::element( 'br' ) . "\n" - ); - } + $this->deduplicateWatchlistEntries( $objOldUser, $objNewUser ); - foreach ( $textUpdateFields as $textUpdateField ) { + foreach ( $updateFields as $fieldInfo ) { + $tableName = array_shift( $fieldInfo ); + $idField = array_shift( $fieldInfo ); + $dbw->update( - $textUpdateField[0], - array( $textUpdateField[1] => $newuser_text ), - array( $textUpdateField[1] => $olduser_text ) + $tableName, + array( $idField => $newuserID ) + array_fill_keys( $fieldInfo, $newuser_text ), + array( $idField => $olduserID ), + __METHOD__ ); + $out->addHTML( - $this->msg( 'usermerge-updating', $textUpdateField[0], $olduser_text, $newuser_text )->escaped() . + $this->msg( + 'usermerge-updating', + $tableName, + $olduserID, + $newuserID + )->escaped() . Html::element( 'br' ) . "\n" ); + + foreach ( $fieldInfo as $textField ) { + $out->addHTML( + $this->msg( + 'usermerge-updating', + $tableName, + $olduser_text, + $newuser_text + )->escaped() . + Html::element( 'br' ) . "\n" + ); + } } $dbw->delete( 'user_newtalk', array( 'user_id' => $olduserID ) ); -- To view, visit https://gerrit.wikimedia.org/r/69017 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibb36ef49e99246e502835f51ab6776422b62438d Gerrit-PatchSet: 16 Gerrit-Project: mediawiki/extensions/UserMerge Gerrit-Branch: master Gerrit-Owner: Parent5446 <[email protected]> Gerrit-Reviewer: Nikerabbit <[email protected]> Gerrit-Reviewer: Parent5446 <[email protected]> Gerrit-Reviewer: Wikinaut <[email protected]> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
