From: Umherirrender Date: Tue, 10 Sep 2019 17:42:58 +0000 (+0200) Subject: Fill GenderCache for used pages in action=query&prop=fileusage X-Git-Tag: 1.34.0-rc.0~89^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/%24oldLink?a=commitdiff_plain;h=a8525d7201dada88f3117142fe1919d0b9b80d4e;p=lhc%2Fweb%2Fwiklou.git Fill GenderCache for used pages in action=query&prop=fileusage Add an utility function ApiQueryBase::executeGenderCacheFromResultWrapper GenderCache stops working when there are more than 1000 cache missed and returning the default value (T200238) Fill the cache with all needed users avoids this behaviour and it saves one query per user page. Change-Id: I911dcb160a7b169091b9e8f66fb3908d0f2a1ba4 --- diff --git a/includes/api/ApiQueryBacklinksprop.php b/includes/api/ApiQueryBacklinksprop.php index b8672ee6b7..022fd9b848 100644 --- a/includes/api/ApiQueryBacklinksprop.php +++ b/includes/api/ApiQueryBacklinksprop.php @@ -286,6 +286,8 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { $res = $this->select( __METHOD__ ); if ( is_null( $resultPageSet ) ) { + $this->executeGenderCacheFromResultWrapper( $res, __METHOD__ ); + $count = 0; foreach ( $res as $row ) { if ( ++$count > $params['limit'] ) { diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 8d9cb48c1a..059c438a37 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\IResultWrapper; @@ -569,6 +570,42 @@ abstract class ApiQueryBase extends ApiBase { ); } + /** + * Preprocess the result set to fill the GenderCache with the necessary information + * before using self::addTitleInfo + * + * @param IResultWrapper $res Result set to work on. + * The result set must have _namespace and _title fields with the provided field prefix + * @param string $fname The caller function name, always use __METHOD__ + * @param string $fieldPrefix Prefix for fields to check gender for + */ + protected function executeGenderCacheFromResultWrapper( + IResultWrapper $res, $fname = __METHOD__, $fieldPrefix = 'page' + ) { + if ( !$res->numRows() ) { + return; + } + + $services = MediaWikiServices::getInstance(); + $nsInfo = $services->getNamespaceInfo(); + $namespaceField = $fieldPrefix . '_namespace'; + $titleField = $fieldPrefix . '_title'; + + $usernames = []; + foreach ( $res as $row ) { + if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) { + $usernames[] = $row->$titleField; + } + } + + if ( $usernames === [] ) { + return; + } + + $genderCache = $services->getGenderCache(); + $genderCache->doQuery( $usernames, $fname ); + } + /** @} */ /************************************************************************//**