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
This commit is contained in:
parent
af2f7e00c3
commit
a43af3bc0e
3 changed files with 22 additions and 2 deletions
|
|
@ -1570,8 +1570,7 @@ class WikiRevision {
|
|||
}
|
||||
|
||||
// avoid memory leak...?
|
||||
$linkCache = LinkCache::singleton();
|
||||
$linkCache->clear();
|
||||
Title::clearCaches();
|
||||
|
||||
$page = WikiPage::factory( $this->title );
|
||||
$page->loadPageData( 'fromdbmaster' );
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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' );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue