r10526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10525‎ | r10526 | r10527 >
Date:13:06, 15 August 2005
Author:timstarling
Status:old
Tags:
Comment:
Always use reference assignment when taking the return value of wfGetDB(), or else annoying bugs which are difficult to track down will result. Example of correct usage:

$dbr =& wfGetDB( DB_SLAVE );
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/LinkCache.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -486,7 +486,7 @@
487487 * Get the database which should be used for reads
488488 */
489489 function &getDB() {
490 - $ret = wfGetDB( DB_MASTER );
 490+ $ret =& wfGetDB( DB_MASTER );
491491 return $ret;
492492 #if ( $this->mForUpdate ) {
493493 $ret =& wfGetDB( DB_MASTER );
@@ -854,7 +854,7 @@
855855 function addTrackbacks() {
856856 global $wgOut, $wgUser;
857857
858 - $dbr = wfGetDB(DB_SLAVE);
 858+ $dbr =& wfGetDB(DB_SLAVE);
859859 $tbs = $dbr->select(
860860 /* FROM */ 'trackbacks',
861861 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
@@ -900,7 +900,7 @@
901901 return;
902902 }
903903
904 - $db = wfGetDB(DB_MASTER);
 904+ $db =& wfGetDB(DB_MASTER);
905905 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
906906 $wgTitle->invalidateCache();
907907 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
Index: trunk/phase3/includes/Parser.php
@@ -2384,7 +2384,7 @@
23852385 }
23862386
23872387 function fetchScaryTemplateMaybeFromCache($url) {
2388 - $dbr = wfGetDB(DB_SLAVE);
 2388+ $dbr =& wfGetDB(DB_SLAVE);
23892389 $obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
23902390 array('tc_url' => $url));
23912391 if ($obj) {
@@ -2399,7 +2399,7 @@
24002400 if (!$text)
24012401 return wfMsg('scarytranscludefailed', $url);
24022402
2403 - $dbw = wfGetDB(DB_MASTER);
 2403+ $dbw =& wfGetDB(DB_MASTER);
24042404 $dbw->replace('transcache', array(), array(
24052405 'tc_url' => $url,
24062406 'tc_time' => time(),
Index: trunk/phase3/includes/LinkCache.php
@@ -388,7 +388,7 @@
389389
390390 // Construct query
391391 // This is very similar to Parser::replaceLinkHolders
392 - $dbr = wfGetDB( DB_SLAVE );
 392+ $dbr =& wfGetDB( DB_SLAVE );
393393 $page = $dbr->tableName( 'page' );
394394 $sql = "SELECT page_id, page_namespace, page_title FROM $page WHERE "
395395 . $this->constructSet( 'page', $dbr );

Status & tagging log