Reset Title cache when importing titles.
authordaniel <daniel.kinzler@wikimedia.de>
Sun, 24 May 2015 15:50:24 +0000 (17:50 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Sun, 24 May 2015 15:55:08 +0000 (17:55 +0200)
WikiImporter now uses NaiveImportTitleFactory, which in turn uses Title::makeTitleSafe,
bypassing the internal title cache. To avoid (potentially cached) Title objects obtained
via Title::newFromText getting out of sync, WikiImporter now clears the title
cache in addition to clearing the LinkCache.

NOTE: a test for this is provided by I2be12fa7d439b.

Bug: T89307
Change-Id: Ib50c48d4797fc21c62090c0be69e87f7e7d07428

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' );
+       }
 }