filerepo: make LocalRepo::getSharedCacheKey() use makeGlobalKey()

Also rename image_redirect key to file_redirect while at it.
This assures that stale keys are not still in use.

Bug: T253405
Change-Id: I31a9bb6672b33fbfa1b974955d78fdfd8d58f5da
This commit is contained in:
Aaron Schulz 2020-05-23 09:47:11 -07:00 committed by Krinkle
parent 820bed0fee
commit 88e17d3f7c
2 changed files with 9 additions and 6 deletions

View file

@ -197,9 +197,9 @@ class LocalRepo extends FileRepo {
public function checkRedirect( Title $title ) { public function checkRedirect( Title $title ) {
$title = File::normalizeTitle( $title, 'exception' ); $title = File::normalizeTitle( $title, 'exception' );
$memcKey = $this->getSharedCacheKey( 'image_redirect', md5( $title->getDBkey() ) ); $memcKey = $this->getSharedCacheKey( 'file_redirect', md5( $title->getDBkey() ) );
if ( $memcKey === false ) { if ( $memcKey === false ) {
$memcKey = $this->getLocalCacheKey( 'image_redirect', md5( $title->getDBkey() ) ); $memcKey = $this->getLocalCacheKey( 'file_redirect', md5( $title->getDBkey() ) );
$expiry = 300; // no invalidation, 5 minutes $expiry = 300; // no invalidation, 5 minutes
} else { } else {
$expiry = 86400; // has invalidation, 1 day $expiry = 86400; // has invalidation, 1 day
@ -497,7 +497,10 @@ class LocalRepo extends FileRepo {
* @return string * @return string
*/ */
public function getSharedCacheKey( ...$args ) { public function getSharedCacheKey( ...$args ) {
return $this->wanCache->makeKey( ...$args ); return $this->wanCache->makeGlobalKey(
WikiMap::getCurrentWikiDbDomain()->getId(),
...$args
);
} }
/** /**
@ -507,7 +510,7 @@ class LocalRepo extends FileRepo {
* @return void * @return void
*/ */
public function invalidateImageRedirect( Title $title ) { public function invalidateImageRedirect( Title $title ) {
$key = $this->getSharedCacheKey( 'image_redirect', md5( $title->getDBkey() ) ); $key = $this->getSharedCacheKey( 'file_redirect', md5( $title->getDBkey() ) );
if ( $key ) { if ( $key ) {
$this->getMasterDB()->onTransactionPreCommitOrIdle( $this->getMasterDB()->onTransactionPreCommitOrIdle(
function () use ( $key ) { function () use ( $key ) {

View file

@ -177,8 +177,8 @@ class LocalRepoTest extends MediaWikiIntegrationTestCase {
->setMethods( [ 'makeKey' ] ) ->setMethods( [ 'makeKey' ] )
->getMock(); ->getMock();
$mockWan->expects( $this->exactly( 2 ) )->method( 'makeKey' )->withConsecutive( $mockWan->expects( $this->exactly( 2 ) )->method( 'makeKey' )->withConsecutive(
[ 'image_redirect', md5( 'Redirect' ) ], [ 'file_redirect', md5( 'Redirect' ) ],
[ 'filerepo', 'local', 'image_redirect', md5( 'Redirect' ) ] [ 'filerepo', 'local', 'file_redirect', md5( 'Redirect' ) ]
)->will( $this->onConsecutiveCalls( false, 'somekey' ) ); )->will( $this->onConsecutiveCalls( false, 'somekey' ) );
$repo = $this->newRepo( [ 'wanCache' => $mockWan ] ); $repo = $this->newRepo( [ 'wanCache' => $mockWan ] );