MediaWiki r32466 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r32465‎ | r32466 (on ViewVC)‎ | 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:

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryDeletedrevs.php	(revision 32465)
+++ trunk/phase3/includes/api/ApiQueryDeletedrevs.php	(revision 32466)
@@ -111,8 +111,6 @@
 
 		$this->addOption('LIMIT', $params['limit'] + 1);
 		$this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
-		if(isset($params['namespace']))
-			$this->addWhereFld('ar_namespace', $params['namespace']);
 		$res = $this->select(__METHOD__);
 		$pages = array();
 		$count = 0;
@@ -183,10 +181,6 @@
 				),
 				ApiBase :: PARAM_DFLT => 'older'
 			),
-			'namespace' => array(
-				ApiBase :: PARAM_ISMULTI => true,
-				ApiBase :: PARAM_TYPE => 'namespace'
-			),
 			'limit' => array(
 				ApiBase :: PARAM_DFLT => 10,
 				ApiBase :: PARAM_TYPE => 'limit',
@@ -215,7 +209,6 @@
 			'start' => 'The timestamp to start enumerating from',
 			'end' => 'The timestamp to stop enumerating at',
 			'dir' => 'The direction in which to enumerate',
-			'namespace' => 'The namespaces to search in',
 			'limit' => 'The maximum amount of revisions to list',
 			'prop' => 'Which properties to get'
 		);
@@ -227,8 +220,8 @@
 
 	protected function getExamples() {
 		return array (
-			'List the first 50 deleted revisions in the Category and Category talk namespaces',
-			'  api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',
+			'List the first 50 deleted revisions',
+			'  api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50',
 			'List the last deleted revisions of Main Page and Talk:Main Page, with content:',
 			'  api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
 		);
Index: trunk/phase3/includes/api/ApiQueryBase.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryBase.php	(revision 32465)
+++ trunk/phase3/includes/api/ApiQueryBase.php	(revision 32466)
@@ -111,8 +111,11 @@
 		if (!is_null($end))
 			$this->addWhere($field . $before . $db->addQuotes($end));
 		
+		$order = $field . ($isDirNewer ? '' : ' DESC');
 		if (!isset($this->options['ORDER BY']))
-			$this->addOption('ORDER BY', $field . ($isDirNewer ? '' : ' DESC'));
+			$this->addOption('ORDER BY', $order);
+		else
+			$this->addOption('ORDER BY', $this->options['ORDER BY'] . ', ' . $order);
 	}
 
 	protected function addOption($name, $value = null) {
@@ -134,6 +137,18 @@
 		return $res;
 	}
 
+	protected function checkRowCount() {
+		$db = $this->getDB();
+		$this->profileDBIn();
+		$rowcount = $db->estimateRowCount($this->tables, $this->fields, $this->where, __METHOD__, $this->options);
+		$this->profileDBOut();
+		
+		global $wgAPIMaxDBRows;
+		if($rowcount > $wgAPIMaxDBRows)
+			return false;
+		return true;
+	}
+
 	public static function addTitleInfo(&$arr, $title, $prefix='') {
 		$arr[$prefix . 'ns'] = intval($title->getNamespace());
 		$arr[$prefix . 'title'] = $title->getPrefixedText();
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryUserContributions.php	(revision 32465)
+++ trunk/phase3/includes/api/ApiQueryUserContributions.php	(revision 32466)
@@ -62,10 +62,6 @@
 
 		if(isset($this->params['userprefix']))
 		{
-			global $wgAPIUCUserPrefixMinLength;
-			if(strlen($this->params['userprefix']) < $wgAPIUCUserPrefixMinLength)
-				$this->dieUsage("User prefixes must be at least $wgAPIUCUserPrefixMinLength characters", 'userprefix-tooshort');
-
 			$this->prefixMode = true;
 			$this->userprefix = $this->params['userprefix'];
 		}
@@ -145,6 +141,9 @@
 		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']);
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 32465)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 32466)
@@ -2877,10 +2877,10 @@
 $wgAPIModules = array();
 
 /**
- * Minimum length of list=usercontribs's ucuserprefix parameter
- * Setting this to a low value can open DOS windows on large wikis
+ * Maximum amount of rows to scan in a DB query in the API
+ * The default value is generally fine
  */
-$wgAPIUCUserPrefixMinLength = 3;
+$wgAPIMaxDBRows = 5000;
 
 /**
  * Parser test suite files to be run by parserTests.php when no specific
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 32465)
+++ trunk/phase3/RELEASE-NOTES	(revision 32466)
@@ -167,6 +167,7 @@
 * Added inprop=talkid,subjectid to prop=info
 * Added help text message that specifies whether a module is POST-only
 * Added createonly parameter to action=edit
+* Replaced $wgAPIUCUserPrefixMinLength by the more generic $wgAPIMaxDBRows
 
 === Languages updated in 1.13 ===
 

Status & tagging log

  • 15:25, 12 September 2011 Meno25 (Talk | contribs) changed the status of r32466 [removed: ok added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox