diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2021-12-16 16:52:52 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2021-12-16 16:52:52 +0000 |
commit | b61d33635a0adb2ed3acd2cc6f139a587d3f213d (patch) | |
tree | 7a176750edb51a22b511bb01bc328b7f0a3647f1 | |
parent | f3400f4289686aa04c56752b96533d204c4ec988 (diff) | |
parent | f010b324c6773e8d7dd82e782d766a4e93f6f859 (diff) |
Merge "Revision: Add two caching layers to loadSlotRecords for template pages" into wmf/1.38.0-wmf.13
-rw-r--r-- | includes/Revision/RevisionStore.php | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/includes/Revision/RevisionStore.php b/includes/Revision/RevisionStore.php index 8491dfa83464..d3860a32e740 100644 --- a/includes/Revision/RevisionStore.php +++ b/includes/Revision/RevisionStore.php @@ -41,6 +41,7 @@ use MediaWiki\DAO\WikiAwareEntity; use MediaWiki\HookContainer\HookContainer; use MediaWiki\HookContainer\HookRunner; use MediaWiki\Linker\LinkTarget; +use MediaWiki\MediaWikiServices; use MediaWiki\Page\LegacyArticleIdAccess; use MediaWiki\Page\PageIdentity; use MediaWiki\Page\PageIdentityValue; @@ -1366,6 +1367,50 @@ class RevisionStore * @return SlotRecord[] */ private function loadSlotRecords( $revId, $queryFlags, PageIdentity $page ) { + // TODO: Find a way to add NS_MODULE from Scribunto here + if ( $page->getNamespace() !== NS_TEMPLATE ) { + $res = $this->loadSlotRecordsFromDb( $revId, $queryFlags, $page ); + return $this->constructSlotRecords( $revId, $res, $queryFlags, $page ); + } + + // TODO: These caches should not be needed. See T297147#7563670 + $localCache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); + $res = $localCache->getWithSetCallback( + $localCache->makeKey( + 'revision-slots', + $page->getWikiId(), + $page->getId( $page->getWikiId() ), + $revId + ), + $localCache::TTL_HOUR, + function () use ( $revId, $queryFlags, $page ) { + return $this->cache->getWithSetCallback( + $this->cache->makeKey( + 'revision-slots', + $page->getWikiId(), + $page->getId( $page->getWikiId() ), + $revId + ), + WANObjectCache::TTL_DAY, + function () use ( $revId, $queryFlags, $page ) { + $res = $this->loadSlotRecordsFromDb( $revId, $queryFlags, $page ); + if ( !$res ) { + // Avoid caching + return false; + } + return $res; + } + ); + } + ); + if ( !$res ) { + $res = []; + } + + return $this->constructSlotRecords( $revId, $res, $queryFlags, $page ); + } + + private function loadSlotRecordsFromDb( $revId, $queryFlags, PageIdentity $page ): array { $revQuery = $this->getSlotsQueryInfo( [ 'content' ] ); list( $dbMode, $dbOptions ) = DBAccessObjectUtils::getDBOptions( $queryFlags ); @@ -1397,8 +1442,7 @@ class RevisionStore $page ); } - - return $this->constructSlotRecords( $revId, $res, $queryFlags, $page ); + return iterator_to_array( $res ); } /** @@ -1503,9 +1547,6 @@ class RevisionStore $this->constructSlotRecords( $revId, $slotRows, $queryFlags, $page ) ); } else { - // XXX: do we need the same kind of caching here - // that getKnownCurrentRevision uses (if $revId == page_latest?) - $slots = new RevisionSlots( function () use( $revId, $queryFlags, $page ) { return $this->loadSlotRecords( $revId, $queryFlags, $page ); } ); |