r32466 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32465‎ | r32466 | r32467 >
Date:13:43, 26 March 2008
Author:catrope
Status:old
Tags:
Comment:
API performance enhancements (bug 13511):
* Replaced $wgAPIUCUserPrefixMinLength with the more generic $wgAPIMaxDBRows
* Added ApiBase::checkRowCount() which checks whether the amount of rows to be scanned is acceptable (i.e. <$wgAPIMaxDBRows). Not using this anywhere (yet?), but it's nice to have
* Killed a filesort in the usercontribs query, query is now indexed nicely
* Dropped the minimum length for ucuserprefix since it's no longer needed (query optimized)
* Removed drnamespace from list=deletedrevs (filesorts 8M rows for drnamespace=0)
* Support multiple orderings in ApiBase::addWhereRange()
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -111,8 +111,6 @@
112112
113113 $this->addOption('LIMIT', $params['limit'] + 1);
114114 $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
115 - if(isset($params['namespace']))
116 - $this->addWhereFld('ar_namespace', $params['namespace']);
117115 $res = $this->select(__METHOD__);
118116 $pages = array();
119117 $count = 0;
@@ -183,10 +181,6 @@
184182 ),
185183 ApiBase :: PARAM_DFLT => 'older'
186184 ),
187 - 'namespace' => array(
188 - ApiBase :: PARAM_ISMULTI => true,
189 - ApiBase :: PARAM_TYPE => 'namespace'
190 - ),
191185 'limit' => array(
192186 ApiBase :: PARAM_DFLT => 10,
193187 ApiBase :: PARAM_TYPE => 'limit',
@@ -215,7 +209,6 @@
216210 'start' => 'The timestamp to start enumerating from',
217211 'end' => 'The timestamp to stop enumerating at',
218212 'dir' => 'The direction in which to enumerate',
219 - 'namespace' => 'The namespaces to search in',
220213 'limit' => 'The maximum amount of revisions to list',
221214 'prop' => 'Which properties to get'
222215 );
@@ -227,8 +220,8 @@
228221
229222 protected function getExamples() {
230223 return array (
231 - 'List the first 50 deleted revisions in the Category and Category talk namespaces',
232 - ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',
 224+ 'List the first 50 deleted revisions',
 225+ ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50',
233226 'List the last deleted revisions of Main Page and Talk:Main Page, with content:',
234227 ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
235228 );
Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -111,8 +111,11 @@
112112 if (!is_null($end))
113113 $this->addWhere($field . $before . $db->addQuotes($end));
114114
 115+ $order = $field . ($isDirNewer ? '' : ' DESC');
115116 if (!isset($this->options['ORDER BY']))
116 - $this->addOption('ORDER BY', $field . ($isDirNewer ? '' : ' DESC'));
 117+ $this->addOption('ORDER BY', $order);
 118+ else
 119+ $this->addOption('ORDER BY', $this->options['ORDER BY'] . ', ' . $order);
117120 }
118121
119122 protected function addOption($name, $value = null) {
@@ -134,6 +137,18 @@
135138 return $res;
136139 }
137140
 141+ protected function checkRowCount() {
 142+ $db = $this->getDB();
 143+ $this->profileDBIn();
 144+ $rowcount = $db->estimateRowCount($this->tables, $this->fields, $this->where, __METHOD__, $this->options);
 145+ $this->profileDBOut();
 146+
 147+ global $wgAPIMaxDBRows;
 148+ if($rowcount > $wgAPIMaxDBRows)
 149+ return false;
 150+ return true;
 151+ }
 152+
138153 public static function addTitleInfo(&$arr, $title, $prefix='') {
139154 $arr[$prefix . 'ns'] = intval($title->getNamespace());
140155 $arr[$prefix . 'title'] = $title->getPrefixedText();
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -62,10 +62,6 @@
6363
6464 if(isset($this->params['userprefix']))
6565 {
66 - global $wgAPIUCUserPrefixMinLength;
67 - if(strlen($this->params['userprefix']) < $wgAPIUCUserPrefixMinLength)
68 - $this->dieUsage("User prefixes must be at least $wgAPIUCUserPrefixMinLength characters", 'userprefix-tooshort');
69 -
7066 $this->prefixMode = true;
7167 $this->userprefix = $this->params['userprefix'];
7268 }
@@ -145,6 +141,9 @@
146142 else
147143 $this->addWhereFld( 'rev_user_text', $this->usernames );
148144 // ... and in the specified timeframe.
 145+ // Ensure the same sort order for rev_user_text and rev_timestamp
 146+ // so our query is indexed
 147+ $this->addWhereRange('rev_user_text', $this->params['dir'], null, null);
149148 $this->addWhereRange('rev_timestamp',
150149 $this->params['dir'], $this->params['start'], $this->params['end'] );
151150 $this->addWhereFld('page_namespace', $this->params['namespace']);
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2877,10 +2877,10 @@
28782878 $wgAPIModules = array();
28792879
28802880 /**
2881 - * Minimum length of list=usercontribs's ucuserprefix parameter
2882 - * Setting this to a low value can open DOS windows on large wikis
 2881+ * Maximum amount of rows to scan in a DB query in the API
 2882+ * The default value is generally fine
28832883 */
2884 -$wgAPIUCUserPrefixMinLength = 3;
 2884+$wgAPIMaxDBRows = 5000;
28852885
28862886 /**
28872887 * Parser test suite files to be run by parserTests.php when no specific
Index: trunk/phase3/RELEASE-NOTES
@@ -167,6 +167,7 @@
168168 * Added inprop=talkid,subjectid to prop=info
169169 * Added help text message that specifies whether a module is POST-only
170170 * Added createonly parameter to action=edit
 171+* Replaced $wgAPIUCUserPrefixMinLength by the more generic $wgAPIMaxDBRows
171172
172173 === Languages updated in 1.13 ===
173174

Status & tagging log