From 0ea2c387271fb4bd4992764006f5d4ce9408ea89 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Wed, 16 May 2012 16:46:22 +0200 Subject: [PATCH] Fill GenderCache inside ApiPageSet the queries for title and pageids are own queries created by the api, which does not use the GenderCache, that can produce a query per row Change-Id: I932f8d9d1cfa751dbb6f5237e2de325527d3ff53 --- includes/api/ApiPageSet.php | 18 ++++++++++++++++++ includes/cache/GenderCache.php | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index cc86c76a36..598f9ada25 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -481,6 +481,7 @@ class ApiPageSet extends ApiQueryBase { ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' ); } + $usernames = array(); if ( $res ) { foreach ( $res as $row ) { $pageId = intval( $row->page_id ); @@ -496,6 +497,11 @@ class ApiPageSet extends ApiQueryBase { // Store any extra fields requested by modules $this->processDbRow( $row ); + + // Need gender information + if( MWNamespace::hasGenderDistinction( $row->page_namespace ) ) { + $usernames[] = $row->page_title; + } } } @@ -510,6 +516,11 @@ class ApiPageSet extends ApiQueryBase { $this->mMissingTitles[$this->mFakePageId] = $title; $this->mFakePageId--; $this->mTitles[] = $title; + + // need gender information + if( MWNamespace::hasGenderDistinction( $ns ) ) { + $usernames[] = $dbkey; + } } } } else { @@ -521,6 +532,10 @@ class ApiPageSet extends ApiQueryBase { } } } + + // Get gender information + $genderCache = GenderCache::singleton(); + $genderCache->doQuery( $usernames, __METHOD__ ); } /** @@ -664,6 +679,9 @@ class ApiPageSet extends ApiQueryBase { * @return LinkBatch */ private function processTitlesArray( $titles ) { + $genderCache = GenderCache::singleton(); + $genderCache->doTitlesArray( $titles, __METHOD__ ); + $linkBatch = new LinkBatch(); foreach ( $titles as $title ) { diff --git a/includes/cache/GenderCache.php b/includes/cache/GenderCache.php index 6a9ecd2fa9..2a169bb3ac 100644 --- a/includes/cache/GenderCache.php +++ b/includes/cache/GenderCache.php @@ -111,6 +111,29 @@ class GenderCache { $this->doQuery( array_keys( $users ), $caller ); } + /** + * Wrapper for doQuery that processes a title or string array. + * + * @since 1.20 + * @param $titles List: array of Title objects or strings + * @param $caller String: the calling method + */ + public function doTitlesArray( $titles, $caller = '' ) { + $users = array(); + foreach ( $titles as $title ) { + $titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title; + if ( !$titleObj ) { + continue; + } + if ( !MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) { + continue; + } + $users[] = $titleObj->getText(); + } + + $this->doQuery( $users, $caller ); + } + /** * Preloads genders for given list of users. * @param $users List|String: usernames -- 2.20.1