Disable statistics update on import with maintenance/importDump.php
authorSubin Siby <subins2000@gmail.com>
Tue, 3 Jan 2017 14:35:34 +0000 (20:05 +0530)
committerSubin Siby <subins2000@gmail.com>
Tue, 3 Jan 2017 14:56:09 +0000 (20:26 +0530)
Disable updating statistics in importDump.php to quickly finish imports from command line.

Bug: T144600
Change-Id: Ib827c068fb20cc03aab47e3106d489f18be1dac6

includes/import/WikiImporter.php
maintenance/importDump.php

index 328cdad..1769924 100644 (file)
@@ -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] )
+                                       ] ) );
+                               }
                        }
                }
 
index f0e0555..6717a8e 100644 (file)
@@ -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 );
                }