r49045 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49044‎ | r49045 | r49046 >
Date:20:04, 30 March 2009
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Kill raw SQL in QueryPage::recache(). I can't find any code that actually calls recache(), though
Modified paths:
  • /trunk/phase3/includes/QueryPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/QueryPage.php
@@ -206,7 +206,7 @@
207207 function recache( $limit, $ignoreErrors = true ) {
208208 $fname = get_class( $this ) . '::recache';
209209 $dbw = wfGetDB( DB_MASTER );
210 - $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
 210+ $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), __METHOD__, 'vslow' ) );
211211 if ( !$dbw || !$dbr ) {
212212 return false;
213213 }
@@ -229,30 +229,23 @@
230230 if ( $res ) {
231231 $num = $dbr->numRows( $res );
232232 # Fetch results
233 - $insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
234 - $first = true;
 233+ $vals = array();
235234 while ( $res && $row = $dbr->fetchObject( $res ) ) {
236 - if ( $first ) {
237 - $first = false;
238 - } else {
239 - $insertSql .= ',';
240 - }
241235 if ( isset( $row->value ) ) {
242236 $value = intval( $row->value ); // @bug 14414
243237 } else {
244238 $value = 0;
245239 }
246 -
247 - $insertSql .= '(' .
248 - $dbw->addQuotes( $row->type ) . ',' .
249 - $dbw->addQuotes( $row->namespace ) . ',' .
250 - $dbw->addQuotes( $row->title ) . ',' .
251 - $dbw->addQuotes( $value ) . ')';
 240+
 241+ $vals[] = array('qc_type' => $row->type,
 242+ 'qc_namespace' => $row->namespace,
 243+ 'qc_title' => $row->title,
 244+ 'qc_value' => $value);
252245 }
253246
254247 # Save results into the querycache table on the master
255 - if ( !$first ) {
256 - if ( !$dbw->query( $insertSql, $fname ) ) {
 248+ if ( count( $vals ) ) {
 249+ if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) {
257250 // Set result to false to indicate error
258251 $dbr->freeResult( $res );
259252 $res = false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r49049Fixed fatal from r49045aaron23:13, 30 March 2009

Comments

#Comment by Tim Starling (talk | contribs)   15:22, 3 June 2009

It's called by maintenance/updateSpecialPages.php.

Status & tagging log