From: Max Semenik Date: Mon, 10 May 2010 15:47:45 +0000 (+0000) Subject: (bug 18488) Added maintenance script refreshCategoryCounts.php. Based on Happy-Mellon... X-Git-Tag: 1.31.0-rc.0~36902 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=1de4e570e1ad0d343cf986b778b73fbc24f3243f;p=lhc%2Fweb%2Fwiklou.git (bug 18488) Added maintenance script refreshCategoryCounts.php. Based on Happy-Mellon's patch from that bug, heavily refactored by me --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 03b93927c1..f3b92d6f6c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -71,6 +71,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 20976) "searchmenu-new-nocreate" message now displayed when when there is no title match in search and the user has no rights to create pages. * (bug 23429) Added new hook WatchlistEditorBuildRemoveLine +* (bug 18488) Added maintenance script refreshCategoryCounts.php === Bug fixes in 1.17 === * (bug 17560) Half-broken deletion moved image files to deletion archive diff --git a/maintenance/refreshCategoryCounts.php b/maintenance/refreshCategoryCounts.php new file mode 100644 index 0000000000..511630225d --- /dev/null +++ b/maintenance/refreshCategoryCounts.php @@ -0,0 +1,102 @@ + r47326); see explanation at + * [https://bugzilla.wikimedia.org/show_bug.cgi?id=17155]. It will print out + * progress indicators every 1000 categories it updates. You may want to use the + * throttling options if it's causing too much load; they will not affect + * correctness. + * + * If the script is stopped and later resumed, you can use the --start option + * with the last printed progress indicator to pick up where you left off. + * This is safe, because any newly-added categories will be added at the end of + * the table. + * + * @file + * @ingroup Maintenance + * @author Happy-melon, Max Semenik + * Based on /maintenance/populateCategory.php by Simetrical. + */ + +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); + +class RefreshCategoryCounts extends Maintenance { + const REPORTING_INTERVAL = 1000; + + public function __construct() { + $this->mDescription = 'Refreshes category counts'; + $this->addOption( 'start', 'Start from this category ID', false, true ); + $this->addOption( 'maxlag', 'Maximum database slave lag in seconds (5 by default)', false, true ); + $this->addOption( 'throttle', 'Optional delay after every processed category in milliseconds', + false, true ); + } + + public function execute() { + $start = intval( $this->getOption( 'start', 0 ) ); + $maxlag = intval( $this->getOption( 'maxlag', 5 ) ); + $throttle = intval( $this->getOption( 'throttle', 0 ) ); + + $this->doRefresh( $start, $maxlag, $throttle ); + } + + protected function doRefresh( $start, $maxlag, $throttle ) { + $dbw = wfGetDB( DB_MASTER ); + + $maxlag = intval( $maxlag ); + $throttle = intval( $throttle ); + $id = $start; + + $i = 0; + while ( true ) { + # Find which category to update + $row = $dbw->selectRow( + 'category', + array( 'cat_id', 'cat_title' ), + 'cat_id > ' . $dbw->addQuotes( $id ), + __METHOD__, + array( 'ORDER BY' => 'cat_id' ) + ); + if ( !$row ) { + # Done, hopefully. + break; + } + $id = $row->cat_id; + $name = $row->cat_title; + + # Use the row to update the category count + $cat = Category::newFromName( $name ); + if ( !is_object( $cat ) ) { + $this->output( "Invalid category name '$name'\n" ); + } else { + $cat->refreshCounts(); + } + + $i++; + if ( !( $i % self::REPORTING_INTERVAL ) ) { + $this->output( "$id\n" ); + wfWaitForSlaves( $maxlag ); + } + usleep( $throttle * 1000 ); + } + + /*if ( $dbw->insert( + 'updatelog', + array( 'ul_key' => 'refresh catgory counts' ), + __METHOD__, + 'IGNORE' + ) + ) { + $this->output( "Category count refresh complete.\n" ); + return true; + } else { + $this->output( "Could not insert category population row.\n" ); + return false; + }*/ + $this->output( "Category count refresh complete.\n" ); + } +} + +$maintClass = "RefreshCategoryCounts"; +require_once( DO_MAINTENANCE ); +