aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api/ApiQueryBase.php
diff options
context:
space:
mode:
authorUmherirrender <umherirrender_de.wp@web.de>2019-09-10 19:42:58 +0200
committerUmherirrender <umherirrender_de.wp@web.de>2019-09-25 21:41:34 +0200
commita8525d7201dada88f3117142fe1919d0b9b80d4e (patch)
treecbde9cc2ff354728640db9016732bd9ab4adc0c7 /includes/api/ApiQueryBase.php
parentbd980451109fb588c30aa5059ddada5ea4f6492e (diff)
downloadmediawikicore-a8525d7201dada88f3117142fe1919d0b9b80d4e.tar.gz
mediawikicore-a8525d7201dada88f3117142fe1919d0b9b80d4e.zip
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
Diffstat (limited to 'includes/api/ApiQueryBase.php')
-rw-r--r--includes/api/ApiQueryBase.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php
index 8d9cb48c1af4..059c438a37ea 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 );
+ }
+
/** @} */
/************************************************************************//**