r23642 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23641‎ | r23642 | r23643 >
Date:14:03, 2 July 2007
Author:catrope
Status:old
Tags:
Comment:
apiedit: API: Caching static intokens and optimizing inprop=lastrevby
Modified paths:
  • /branches/apiedit/phase3/includes/api/ApiQueryInfo.php (modified) (history)

Diff [purge]

Index: branches/apiedit/phase3/includes/api/ApiQueryInfo.php
@@ -72,12 +72,13 @@
7373 $pageLatest = $pageSet->getCustomField('page_latest');
7474 $pageLength = $pageSet->getCustomField('page_len');
7575
 76+ $db = $this->getDB();
7677 if ($fld_protection && count($titles) > 0) {
 78+ // Query all restrictions we need in one go and put them in the $protections array
7779 $this->addTables('page_restrictions');
7880 $this->addFields(array('pr_page', 'pr_type', 'pr_level', 'pr_expiry'));
7981 $this->addWhereFld('pr_page', array_keys($titles));
8082
81 - $db = $this->getDB();
8283 $res = $this->select(__METHOD__);
8384 while($row = $db->fetchObject($res)) {
8485 $protections[$row->pr_page][] = array(
@@ -88,7 +89,21 @@
8990 }
9091 $db->freeResult($res);
9192 }
92 -
 93+
 94+ if($fld_lastrevby || isset($params['tokens']['rollback']))
 95+ {
 96+ // Query all revisions we need in one go and put them in the $lastrevby array
 97+ $this->resetQueryParams();
 98+ $this->addTables('revision');
 99+ $this->addFields(array('rev_id', 'rev_user_text'));
 100+ $this->addWhereFld('rev_id', $pageLatest);
 101+
 102+ $res = $this->select(__METHOD__);
 103+ while($row = $db->fetchObject($res))
 104+ $lastrevby[intval($row->rev_id)] = $row->rev_user_text;
 105+ }
 106+
 107+ $et = null; // Cached edit token is stored here
93108 foreach ( $titles as $pageid => $title ) {
94109 $pageInfo = array (
95110 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
@@ -96,12 +111,10 @@
97112 'counter' => intval($pageCounter[$pageid]),
98113 'length' => intval($pageLength[$pageid])
99114 );
100 - if(isset($params['tokens']) || $fld_lastrevby)
101 - {
102 - $lastrev = Revision::newFromId($pageInfo['lastrevid']);
103 - $pageInfo['lastrevby'] = $lastrev->getUserText();
104 - }
105115
 116+ if($fld_lastrevby)
 117+ $pageInfo['lastrevby'] = $lastrevby[$pageInfo['lastrevid']];
 118+
106119 if ($pageIsRedir[$pageid])
107120 $pageInfo['redirect'] = '';
108121
@@ -124,17 +137,23 @@
125138 switch($token)
126139 {
127140 case 'rollback':
128 - $tokenArr[$token] = $wgUser->editToken(array($title->getPrefixedText(), $pageInfo['lastrevby']));
 141+ $tokenArr[$token] = $wgUser->editToken(array($title->getPrefixedText(), $lastrevby[$pageInfo['lastrevid']]));
129142 break;
130143 case 'edit':
131144 case 'move':
132145 case 'delete':
133146 case 'protect':
134147 case 'unprotect':
135 - if($wgUser->isAnon())
136 - $tokenArr[$token] = EDIT_TOKEN_SUFFIX;
 148+ // All these tokens are constant, so we can cache them
 149+ if(!is_null($et))
 150+ $tokenArr[$token] = $et;
137151 else
138 - $tokenArr[$token] = $wgUser->editToken();
 152+ {
 153+ if($wgUser->isAnon())
 154+ $et = $tokenArr[$token] = EDIT_TOKEN_SUFFIX;
 155+ else
 156+ $et = $tokenArr[$token] = $wgUser->editToken();
 157+ }
139158 // default: can't happen, ignore it if it does happen in some weird way
140159 }
141160 if(count($tokenArr) > 0)
@@ -178,7 +197,7 @@
179198 'prop' => array (
180199 'Which additional properties to get:',
181200 ' "protection" - List the protection level of each page',
182 - ' "lastrevby" - The name of the user who made the last edit. You may need this for action=rollback.'
 201+ ' "lastrevby" - List the name of the user who made the last edit'
183202 ),
184203 'tokens' => 'Which tokens to get.'
185204 );

Status & tagging log