From: Subin Siby Date: Tue, 3 Jan 2017 14:35:34 +0000 (+0530) Subject: Disable statistics update on import with maintenance/importDump.php X-Git-Tag: 1.31.0-rc.0~4420 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%2C%22id_auteur=%24connecte%22%29%20.%20%22?a=commitdiff_plain;h=1f8b491dd200179258ff6b302ed253fa46145f84;p=lhc%2Fweb%2Fwiklou.git Disable statistics update on import with maintenance/importDump.php Disable updating statistics in importDump.php to quickly finish imports from command line. Bug: T144600 Change-Id: Ib827c068fb20cc03aab47e3106d489f18be1dac6 --- diff --git a/includes/import/WikiImporter.php b/includes/import/WikiImporter.php index 328cdadb0b..1769924ab0 100644 --- a/includes/import/WikiImporter.php +++ b/includes/import/WikiImporter.php @@ -45,6 +45,8 @@ class WikiImporter { private $importTitleFactory; /** @var array */ private $countableCache = []; + /** @var bool */ + private $disableStatisticsUpdate = false; /** * Creates an ImportXMLReader drawing from the source provided @@ -303,6 +305,14 @@ class WikiImporter { $this->mImportUploads = $import; } + /** + * Statistics update can cause a lot of time + * @since 1.29 + */ + public function disableStatisticsUpdate() { + $this->disableStatisticsUpdate = true; + } + /** * Default per-page callback. Sets up some things related to site statistics * @param array $titleAndForeignTitle Two-element array, with Title object at @@ -381,21 +391,23 @@ class WikiImporter { // suffers from issues of replica DB lag. We let WikiPage handle the total page // and revision count, and we implement our own custom logic for the // article (content page) count. - $page = WikiPage::factory( $title ); - $page->loadPageData( 'fromdbmaster' ); - $content = $page->getContent(); - if ( $content === null ) { - wfDebug( __METHOD__ . ': Skipping article count adjustment for ' . $title . - ' because WikiPage::getContent() returned null' ); - } else { - $editInfo = $page->prepareContentForEdit( $content ); - $countKey = 'title_' . $title->getPrefixedText(); - $countable = $page->isCountable( $editInfo ); - if ( array_key_exists( $countKey, $this->countableCache ) && - $countable != $this->countableCache[$countKey] ) { - DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ - 'articles' => ( (int)$countable - (int)$this->countableCache[$countKey] ) - ] ) ); + if ( !$this->disableStatisticsUpdate ) { + $page = WikiPage::factory( $title ); + $page->loadPageData( 'fromdbmaster' ); + $content = $page->getContent(); + if ( $content === null ) { + wfDebug( __METHOD__ . ': Skipping article count adjustment for ' . $title . + ' because WikiPage::getContent() returned null' ); + } else { + $editInfo = $page->prepareContentForEdit( $content ); + $countKey = 'title_' . $title->getPrefixedText(); + $countable = $page->isCountable( $editInfo ); + if ( array_key_exists( $countKey, $this->countableCache ) && + $countable != $this->countableCache[$countKey] ) { + DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ + 'articles' => ( (int)$countable - (int)$this->countableCache[$countKey] ) + ] ) ); + } } } diff --git a/maintenance/importDump.php b/maintenance/importDump.php index f0e0555af1..6717a8ebde 100644 --- a/maintenance/importDump.php +++ b/maintenance/importDump.php @@ -109,7 +109,8 @@ TEXT } $this->output( "Done!\n" ); - $this->output( "You might want to run rebuildrecentchanges.php to regenerate RecentChanges\n" ); + $this->output( "You might want to run rebuildrecentchanges.php to regenerate RecentChanges,\n" ); + $this->output( "and initSiteStats.php to update page and revision counts\n" ); } function setNsfilter( array $namespaces ) { @@ -283,6 +284,9 @@ TEXT $source = new ImportStreamSource( $handle ); $importer = new WikiImporter( $source, $this->getConfig() ); + // Updating statistics require a lot of time so disable it + $importer->disableStatisticsUpdate(); + if ( $this->hasOption( 'debug' ) ) { $importer->setDebug( true ); }