r61017 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61016‎ | r61017 | r61018 >
Date:19:45, 13 January 2010
Author:maxsem
Status:ok
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -3631,7 +3631,7 @@
36323632 */
36333633 public static function incViewCount( $id ) {
36343634 $id = intval( $id );
3635 - global $wgHitcounterUpdateFreq, $wgDBtype;
 3635+ global $wgHitcounterUpdateFreq;
36363636
36373637 $dbw = wfGetDB( DB_MASTER );
36383638 $pageTable = $dbw->tableName( 'page' );
@@ -3662,23 +3662,23 @@
36633663 wfProfileIn( 'Article::incViewCount-collect' );
36643664 $old_user_abort = ignore_user_abort( true );
36653665
3666 - if($wgDBtype == 'mysql')
3667 - $dbw->query("LOCK TABLES $hitcounterTable WRITE");
3668 - $tabletype = $wgDBtype == 'mysql' ? "ENGINE=HEAP " : '';
3669 - $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype AS ".
 3666+ $dbType = $dbw->getType();
 3667+ $dbw->lockTables( array(), array( 'hitcounter' ), __METHOD__, false );
 3668+ $tabletype = $dbType == 'mysql' ? "ENGINE=HEAP " : '';
 3669+ $dbw->query( "CREATE TEMPORARY TABLE $acchitsTable $tabletype AS ".
36703670 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
3671 - 'GROUP BY hc_id');
3672 - $dbw->query("DELETE FROM $hitcounterTable");
3673 - if($wgDBtype == 'mysql') {
3674 - $dbw->query('UNLOCK TABLES');
3675 - $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
3676 - 'WHERE page_id = hc_id');
 3671+ 'GROUP BY hc_id', __METHOD__ );
 3672+ $dbw->delete( 'hitcounter', '*', __METHOD__ );
 3673+ $dbw->unlockTables( __METHOD__ );
 3674+ if( $dbType == 'mysql' ) {
 3675+ $dbw->query( "UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
 3676+ 'WHERE page_id = hc_id', __METHOD__ );
36773677 }
36783678 else {
3679 - $dbw->query("UPDATE $pageTable SET page_counter=page_counter + hc_n ".
3680 - "FROM $acchitsTable WHERE page_id = hc_id");
 3679+ $dbw->query( "UPDATE $pageTable SET page_counter=page_counter + hc_n ".
 3680+ "FROM $acchitsTable WHERE page_id = hc_id", __METHOD__ );
36813681 }
3682 - $dbw->query("DROP TABLE $acchitsTable");
 3682+ $dbw->query( "DROP TABLE $acchitsTable", __METHOD__ );
36833683
36843684 ignore_user_abort( $old_user_abort );
36853685 wfProfileOut( 'Article::incViewCount-collect' );

Status & tagging log