From: Roan Kattouw Date: Thu, 10 Apr 2008 11:57:27 +0000 (+0000) Subject: API: Enhancing ucuserprefix performance X-Git-Tag: 1.31.0-rc.0~48463 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=3081fa9a5746aa667a68ee47c6bdc07a357b59e6;p=lhc%2Fweb%2Fwiklou.git API: Enhancing ucuserprefix performance * ucuserprefix now only works for anonymous users. This allows us to add WHERE rev_user=0 (fewer rows to scan) and use the user_timestamp index (so the ORDER BY rev_user_text DESC can be killed) * ucuserprefix must be an IP containing at least two full octets, e.g. '12.345.', to ensure the resulting LIKE is somewhat sane --- diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index 672c16cbf3..f0097b1cd0 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -62,6 +62,8 @@ class ApiQueryContributions extends ApiQueryBase { if(isset($this->params['userprefix'])) { + if(!preg_match('/^\d{1,3}\.\d{1,3}\./', $this->params['userprefix'])) + $this->dieUsage("ucuserprefix must contain at least two octets terminated by a period", 'baduserprefix'); $this->prefixMode = true; $this->userprefix = $this->params['userprefix']; } @@ -137,13 +139,13 @@ class ApiQueryContributions extends ApiQueryBase { $this->addWhereFld('rev_deleted', 0); // We only want pages by the specified users. if($this->prefixMode) + { + $this->addWhere(array('rev_user' => 0)); $this->addWhere("rev_user_text LIKE '" . $this->getDb()->escapeLike($this->userprefix) . "%'"); + } else $this->addWhereFld( 'rev_user_text', $this->usernames ); // ... and in the specified timeframe. - // Ensure the same sort order for rev_user_text and rev_timestamp - // so our query is indexed - $this->addWhereRange('rev_user_text', $this->params['dir'], null, null); $this->addWhereRange('rev_timestamp', $this->params['dir'], $this->params['start'], $this->params['end'] ); $this->addWhereFld('page_namespace', $this->params['namespace']); @@ -268,7 +270,10 @@ class ApiQueryContributions extends ApiQueryBase { 'start' => 'The start timestamp to return from.', 'end' => 'The end timestamp to return to.', 'user' => 'The user to retrieve contributions for.', - 'userprefix' => 'Retrieve contibutions for all users whose names begin with this value. Overrides ucuser.', + 'userprefix' => array( + 'Retrieve contibutions for all IP addresses that begin with this value.', + 'Overrides ucuser. Must contain at least two octets terminated by a period' + ), 'dir' => 'The direction to search (older or newer).', 'namespace' => 'Only list contributions in these namespaces', 'prop' => 'Include additional pieces of information',