Merge "Reset Title cache when importing titles."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sun, 24 May 2015 16:16:30 +0000 (16:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 24 May 2015 16:16:30 +0000 (16:16 +0000)
includes/Import.php
includes/Title.php
tests/phpunit/includes/TitleMethodsTest.php

index c2fae30..ee57a9e 100644 (file)
@@ -1570,8 +1570,7 @@ class WikiRevision {
                }
 
                // avoid memory leak...?
-               $linkCache = LinkCache::singleton();
-               $linkCache->clear();
+               Title::clearCaches();
 
                $page = WikiPage::factory( $this->title );
                $page->loadPageData( 'fromdbmaster' );
index 601211d..d5eff46 100644 (file)
@@ -3309,6 +3309,14 @@ class Title {
                $this->mIsBigDeletion = null;
        }
 
+       public static function clearCaches() {
+               $linkCache = LinkCache::singleton();
+               $linkCache->clear();
+
+               $titleCache = self::getTitleCache();
+               $titleCache->clear();
+       }
+
        /**
         * Capitalize a text string for a title if it belongs to a namespace that capitalizes
         *
index bcdb45a..e186438 100644 (file)
@@ -323,4 +323,17 @@ class TitleMethodsTest extends MediaWikiLangTestCase {
                $title = Title::newFromText( $text );
                $this->assertEquals( $expected, $title->getOtherPage()->getPrefixedText() );
        }
+
+       public function testClearCaches() {
+               $linkCache = LinkCache::singleton();
+
+               $title1 = Title::newFromText( 'Foo' );
+               $linkCache->addGoodLinkObj( 23, $title1 );
+
+               Title::clearCaches();
+
+               $title2 = Title::newFromText( 'Foo' );
+               $this->assertNotSame( $title1, $title2, 'title cache should be empty' );
+               $this->assertEquals( 0, $linkCache->getGoodLinkID( 'Foo' ), 'link cache should be empty' );
+       }
 }