From a43af3bc0e12d99b83a1e0cd2713cf7785f1f33c Mon Sep 17 00:00:00 2001 From: daniel Date: Sun, 24 May 2015 17:50:24 +0200 Subject: [PATCH] Reset Title cache when importing titles. 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 | 3 +-- includes/Title.php | 8 ++++++++ tests/phpunit/includes/TitleMethodsTest.php | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/includes/Import.php b/includes/Import.php index c2fae30952..ee57a9e01e 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -1570,8 +1570,7 @@ class WikiRevision { } // avoid memory leak...? - $linkCache = LinkCache::singleton(); - $linkCache->clear(); + Title::clearCaches(); $page = WikiPage::factory( $this->title ); $page->loadPageData( 'fromdbmaster' ); diff --git a/includes/Title.php b/includes/Title.php index 601211d1b1..d5eff46105 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 * diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index bcdb45aa78..e186438b44 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -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' ); + } } -- 2.20.1