diff options
author | Amir Sarabadani <ladsgroup@gmail.com> | 2021-12-14 09:14:06 +0100 |
---|---|---|
committer | Ladsgroup <Ladsgroup@gmail.com> | 2021-12-14 15:21:04 +0000 |
commit | 6a9160bb09adbd2e3eed924e5ba59c9b82cef6b7 (patch) | |
tree | f9c2d98c92aa60ae513de7b3888ef2717e311c48 | |
parent | f51f68b864d6ed463e5f66fc6e3fa4794b795399 (diff) |
cache: Add four fields to LinkCache::getSelectFields
These are needed PageStoreRecord::REQUIRED_FIELDS and that's why putting
PageStore on top of LinkCache caused a lot of increase in db reads.
Bug: T297669
Change-Id: If77c2f9879d7bae71eb59944efd8b3798d16aa46
-rw-r--r-- | includes/cache/LinkCache.php | 17 | ||||
-rw-r--r-- | tests/phpunit/includes/cache/LinkCacheTest.php | 3 | ||||
-rw-r--r-- | tests/phpunit/includes/page/PageStoreTest.php | 36 |
3 files changed, 12 insertions, 44 deletions
diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index 32ef5611df24..c852525529fb 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -25,6 +25,7 @@ use MediaWiki\Linker\LinkTarget; use MediaWiki\MediaWikiServices; use MediaWiki\Page\PageIdentity; use MediaWiki\Page\PageReference; +use MediaWiki\Page\PageStoreRecord; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -383,14 +384,14 @@ class LinkCache implements LoggerAwareInterface { public static function getSelectFields() { global $wgPageLanguageUseDB; - $fields = [ - 'page_id', - 'page_len', - 'page_is_redirect', - 'page_latest', - 'page_restrictions', - 'page_content_model', - ]; + $fields = array_merge( + PageStoreRecord::REQUIRED_FIELDS, + [ + 'page_len', + 'page_restrictions', + 'page_content_model', + ] + ); if ( $wgPageLanguageUseDB ) { $fields[] = 'page_lang'; diff --git a/tests/phpunit/includes/cache/LinkCacheTest.php b/tests/phpunit/includes/cache/LinkCacheTest.php index ec2994db1351..76a2fdef4683 100644 --- a/tests/phpunit/includes/cache/LinkCacheTest.php +++ b/tests/phpunit/includes/cache/LinkCacheTest.php @@ -42,11 +42,14 @@ class LinkCacheTest extends MediaWikiIntegrationTestCase { private function getPageRow( $offset = 0 ) { return (object)[ 'page_id' => 8 + $offset, + 'page_namespace' => 0, + 'page_title' => 'Test ' . $offset, 'page_len' => 18, 'page_is_redirect' => 0, 'page_latest' => 118 + $offset, 'page_content_model' => CONTENT_MODEL_TEXT, 'page_lang' => 'xyz', + 'page_is_new' => 0, 'page_restrictions' => 'test', 'page_touched' => '20200202020202', ]; diff --git a/tests/phpunit/includes/page/PageStoreTest.php b/tests/phpunit/includes/page/PageStoreTest.php index 75fc56e43770..1e9b7b36d720 100644 --- a/tests/phpunit/includes/page/PageStoreTest.php +++ b/tests/phpunit/includes/page/PageStoreTest.php @@ -289,42 +289,6 @@ class PageStoreTest extends MediaWikiIntegrationTestCase { * Test that we get a PageRecord when an incomplete row exists in the cache * @covers \MediaWiki\Page\PageStore::getPageByName */ - public function testGetPageByName_cachedIncompleteRow() { - $existingPage = $this->getExistingTestPage(); - $ns = $existingPage->getNamespace(); - $dbkey = $existingPage->getDBkey(); - - $linkCache = $this->getServiceContainer()->getLinkCache(); - $linkCache->clearLink( $existingPage ); - - // Has all fields needed by LinkCache, but not all fields needed by PageStore. - // This may happen when legacy code injects rows directly into LinkCache. - // LinkCache::addLinkObj itself produces incomplete rows as well. - $row = (object)[ - 'page_id' => 8, - 'page_is_redirect' => 0, - 'page_latest' => 118, - 'page_len' => 155, - 'page_content_model' => CONTENT_FORMAT_TEXT, - 'page_lang' => 'xyz', - 'page_restrictions' => 'test' - ]; - - $linkCache->addGoodLinkObjFromRow( $existingPage, $row ); - - $pageStore = $this->getPageStore(); - $page = $pageStore->getPageByName( $ns, $dbkey ); - - $this->assertSame( $existingPage->getId(), $page->getId() ); - $this->assertSame( $existingPage->getNamespace(), $page->getNamespace() ); - $this->assertSame( $existingPage->getDBkey(), $page->getDBkey() ); - $this->assertSame( $existingPage->getLatest(), $page->getLatest() ); - } - - /** - * Test that we get a PageRecord when an incomplete row exists in the cache - * @covers \MediaWiki\Page\PageStore::getPageByName - */ public function testGetPageByName_cachedFakeRow() { $nonexistingPage = $this->getNonexistingTestPage(); $ns = $nonexistingPage->getNamespace(); |