http://www.mediawiki.org/wiki/Special:Code/MediaWiki/61017
Revision: 61017 Author: maxsem Date: 2010-01-13 19:45:11 +0000 (Wed, 13 Jan 2010) Log Message: ----------- Refactoring of Article::incViewCount(): use Database::getType() instead of $wgDBtype, and lockTables() instead of constructing SQL manually Modified Paths: -------------- trunk/phase3/includes/Article.php Modified: trunk/phase3/includes/Article.php =================================================================== --- trunk/phase3/includes/Article.php 2010-01-13 19:42:24 UTC (rev 61016) +++ trunk/phase3/includes/Article.php 2010-01-13 19:45:11 UTC (rev 61017) @@ -3631,7 +3631,7 @@ */ public static function incViewCount( $id ) { $id = intval( $id ); - global $wgHitcounterUpdateFreq, $wgDBtype; + global $wgHitcounterUpdateFreq; $dbw = wfGetDB( DB_MASTER ); $pageTable = $dbw->tableName( 'page' ); @@ -3662,23 +3662,23 @@ wfProfileIn( 'Article::incViewCount-collect' ); $old_user_abort = ignore_user_abort( true ); - if($wgDBtype == 'mysql') - $dbw->query("LOCK TABLES $hitcounterTable WRITE"); - $tabletype = $wgDBtype == 'mysql' ? "ENGINE=HEAP " : ''; - $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype AS ". + $dbType = $dbw->getType(); + $dbw->lockTables( array(), array( 'hitcounter' ), __METHOD__, false ); + $tabletype = $dbType == 'mysql' ? "ENGINE=HEAP " : ''; + $dbw->query( "CREATE TEMPORARY TABLE $acchitsTable $tabletype AS ". "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ". - 'GROUP BY hc_id'); - $dbw->query("DELETE FROM $hitcounterTable"); - if($wgDBtype == 'mysql') { - $dbw->query('UNLOCK TABLES'); - $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ". - 'WHERE page_id = hc_id'); + 'GROUP BY hc_id', __METHOD__ ); + $dbw->delete( 'hitcounter', '*', __METHOD__ ); + $dbw->unlockTables( __METHOD__ ); + if( $dbType == 'mysql' ) { + $dbw->query( "UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ". + 'WHERE page_id = hc_id', __METHOD__ ); } else { - $dbw->query("UPDATE $pageTable SET page_counter=page_counter + hc_n ". - "FROM $acchitsTable WHERE page_id = hc_id"); + $dbw->query( "UPDATE $pageTable SET page_counter=page_counter + hc_n ". + "FROM $acchitsTable WHERE page_id = hc_id", __METHOD__ ); } - $dbw->query("DROP TABLE $acchitsTable"); + $dbw->query( "DROP TABLE $acchitsTable", __METHOD__ ); ignore_user_abort( $old_user_abort ); wfProfileOut( 'Article::incViewCount-collect' ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs