r69226 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69225‎ | r69226 | r69227 >
Date:08:14, 10 July 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Clean up query code
Modified paths:
  • /trunk/phase3/includes/LinkBatch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LinkBatch.php
@@ -136,23 +136,19 @@
137137 }
138138 wfProfileIn( __METHOD__ );
139139
140 - // Construct query
141 - // This is very similar to Parser::replaceLinkHolders
 140+ // This is similar to LinkHolderArray::replaceInternal
142141 $dbr = wfGetDB( DB_SLAVE );
143 - $page = $dbr->tableName( 'page' );
144 - $set = $this->constructSet( 'page', $dbr );
145 - if ( $set === false ) {
146 - wfProfileOut( __METHOD__ );
147 - return false;
148 - }
149 - $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest FROM $page WHERE $set";
 142+ $table = 'page';
 143+ $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_len',
 144+ 'page_is_redirect', 'page_latest' );
 145+ $conds = $this->constructSet( 'page', $dbr );
150146
151147 // Do query
152148 $caller = __METHOD__;
153149 if ( strval( $this->caller ) !== '' ) {
154150 $caller .= " (for {$this->caller})";
155151 }
156 - $res = $dbr->query( $sql, $caller );
 152+ $res = $dbr->select( $table, $fields, $conds, $caller );
157153 wfProfileOut( __METHOD__ );
158154 return $res;
159155 }
@@ -165,6 +161,6 @@
166162 * @return mixed string with SQL where clause fragment, or false if no items.
167163 */
168164 public function constructSet( $prefix, $db ) {
169 - return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
 165+ return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
170166 }
171167 }

Status & tagging log