Tpt has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392207 )
Change subject: Cleans up DatabaseIndexForPageLookup ...................................................................... Cleans up DatabaseIndexForPageLookup Change-Id: Ie0f40d740d8e529a1d465e796cf43259949f9deb --- M includes/index/ProofreadIndexDbConnector.php M includes/page/DatabaseIndexForPageLookup.php 2 files changed, 26 insertions(+), 41 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage refs/changes/07/392207/1 diff --git a/includes/index/ProofreadIndexDbConnector.php b/includes/index/ProofreadIndexDbConnector.php index 6ff1bc7..ffd44a4 100644 --- a/includes/index/ProofreadIndexDbConnector.php +++ b/includes/index/ProofreadIndexDbConnector.php @@ -22,26 +22,6 @@ class ProofreadIndexDbConnector { /** - * Query the database to find if the current page is referred in an Index page. - * @param Title $title - * @return ResultWrapper - */ - public static function getRowsFromTitle( Title $title ) { - $dbr = wfGetDB( DB_REPLICA ); - $result = $dbr->select( - [ 'page', 'pagelinks' ], - [ 'page_namespace', 'page_title' ], - [ - 'pl_namespace' => $title->getNamespace(), - 'pl_title' => $title->getDBkey(), - 'pl_from=page_id' - ], - __METHOD__ - ); - return $result; - } - - /** * @param Object $x * @param int $indexId * @param WikiPage $article diff --git a/includes/page/DatabaseIndexForPageLookup.php b/includes/page/DatabaseIndexForPageLookup.php index 1c5a402..e71a3c2 100644 --- a/includes/page/DatabaseIndexForPageLookup.php +++ b/includes/page/DatabaseIndexForPageLookup.php @@ -2,7 +2,6 @@ namespace ProofreadPage\Page; -use ProofreadIndexDbConnector; use RepoGroup; use Title; @@ -39,14 +38,8 @@ */ public function getIndexForPageTitle( Title $pageTitle ) { $cacheKey = $pageTitle->getDBkey(); - if ( !array_key_exists( $cacheKey, $this->cache ) ) { - $indexTitle = $this->findIndexTitle( $pageTitle ); - if ( $indexTitle === null ) { - $this->cache[$cacheKey] = null; - } else { - $this->cache[$cacheKey] = $indexTitle; - } + $this->cache[$cacheKey] = $this->findIndexTitle( $pageTitle ); } return $this->cache[$cacheKey]; } @@ -55,21 +48,13 @@ $possibleIndexTitle = $this->findPossibleIndexTitleBasedOnName( $pageTitle ); // Try to find links from Index: pages - $result = ProofreadIndexDbConnector::getRowsFromTitle( $pageTitle ); $indexesThatLinksHere = []; - foreach ( $result as $x ) { - $refTitle = Title::makeTitle( $x->page_namespace, $x->page_title ); - if ( $refTitle !== null && - $refTitle->inNamespace( $this->indexNamespaceId ) - ) { - if ( $possibleIndexTitle !== null && - // It is the same as the linked file, we know it's this Index: - $refTitle->equals( $possibleIndexTitle ) - ) { - return $refTitle; - } - $indexesThatLinksHere[] = $refTitle; + foreach ( $this->findIndexesWhichLinkTo( $pageTitle ) as $indexTitle ) { + // It is the same as the linked file, we know it's this Index: + if ( $possibleIndexTitle !== null && $indexTitle->equals( $possibleIndexTitle ) ) { + return $indexTitle; } + $indexesThatLinksHere[] = $indexTitle; } if ( !empty( $indexesThatLinksHere ) ) { // TODO: what should we do if there are more than 1 possible index? @@ -99,4 +84,24 @@ } return null; } + + private function findIndexesWhichLinkTo( Title $title ) { + $results = wfGetDB( DB_REPLICA )->select( + [ 'page', 'pagelinks' ], + [ 'page_namespace', 'page_title' ], + [ + 'pl_namespace' => $title->getNamespace(), + 'pl_title' => $title->getDBkey(), + 'pl_from=page_id', + 'pl_from_namespace' => $this->indexNamespaceId + ], + __METHOD__ + ); + foreach ( $results as $row ) { + $indexTitle = Title::makeTitle( $row->page_namespace, $row->page_title ); + if ( $indexTitle !== null ) { + yield $indexTitle; + } + } + } } -- To view, visit https://gerrit.wikimedia.org/r/392207 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie0f40d740d8e529a1d465e796cf43259949f9deb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ProofreadPage Gerrit-Branch: master Gerrit-Owner: Tpt <thoma...@hotmail.fr> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits