From 8615c705ef1de11a3e75c5bd20cc524063b17ddc Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 23 Sep 2016 20:51:36 -0700 Subject: [PATCH] Avoid DBPerformance log warnings in SpecialEditWatchlist Change-Id: I97b31f5e805e9e3e4192d15195ff26ec416ad6b2 --- includes/specials/SpecialEditWatchlist.php | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index a5a45d5927..0defcd1baf 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -68,8 +68,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { */ private function initServices() { if ( !$this->titleParser ) { - $lang = $this->getContext()->getLanguage(); - $this->titleParser = new MediaWikiTitleCodec( $lang, GenderCache::singleton() ); + $this->titleParser = MediaWikiServices::getInstance()->getTitleParser(); } } @@ -205,7 +204,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } } - GenderCache::singleton()->doTitlesArray( $titles ); + MediaWikiServices::getInstance()->getGenderCache()->doTitlesArray( $titles ); $list = []; /** @var Title $title */ @@ -355,7 +354,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } } - GenderCache::singleton()->doTitlesArray( $titles ); + MediaWikiServices::getInstance()->getGenderCache()->doTitlesArray( $titles ); foreach ( $titles as $title ) { $list[] = $title->getPrefixedText(); @@ -431,20 +430,22 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } $user = $this->getUser(); - $store = MediaWikiServices::getInstance()->getWatchedItemStore(); - - foreach ( $this->badItems as $row ) { - list( $title, $namespace, $dbKey ) = $row; - $action = $title ? 'cleaning up' : 'deleting'; - wfDebug( "User {$user->getName()} has broken watchlist item ns($namespace):$dbKey, $action.\n" ); - - $store->removeWatch( $user, new TitleValue( (int)$namespace, $dbKey ) ); - - // Can't just do an UPDATE instead of DELETE/INSERT due to unique index - if ( $title ) { - $user->addWatch( $title ); + $badItems = $this->badItems; + DeferredUpdates::addCallableUpdate( function () use ( $user, $badItems ) { + $store = MediaWikiServices::getInstance()->getWatchedItemStore(); + foreach ( $badItems as $row ) { + list( $title, $namespace, $dbKey ) = $row; + $action = $title ? 'cleaning up' : 'deleting'; + wfDebug( "User {$user->getName()} has broken watchlist item " . + "ns($namespace):$dbKey, $action.\n" ); + + $store->removeWatch( $user, new TitleValue( (int)$namespace, $dbKey ) ); + // Can't just do an UPDATE instead of DELETE/INSERT due to unique index + if ( $title ) { + $user->addWatch( $title ); + } } - } + } ); } /** -- 2.20.1