Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
]
}
},
"JobClasses": {
"ClearGitInfoCache": "Miraheze\\MirahezeMagic\\Jobs\\ClearGitInfoCache"
},
"Hooks": {
"AbuseFilterShouldFilterAction": {
"handler": "Main"
Expand Down
38 changes: 38 additions & 0 deletions includes/Jobs/ClearGitInfoCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Miraheze\MirahezeMagic\Jobs;

use GenericParameterJob;
use Job;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;

class ClearGitInfoCache extends Job implements GenericParameterJob {

public const JOB_NAME = 'ClearGitInfoCache';

private array $keys;
private string $startWiki;

public function __construct( array $params ) {
parent::__construct( self::JOB_NAME, $params );

$this->startWiki = $params['startWiki'];
$this->keys = $params['keys'];
}

public function run(): bool {
$mediawikiServices = MediaWikiServices::getInstance();
$cache = $mediawikiServices->getObjectCacheFactory()->getInstance( CACHE_ANYTHING );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use service injection


$startWiki = preg_quote( $this->startWiki, '/' );
foreach ( $mediawikiServices->getMainConfig()->get( MainConfigNames::LocalDatabases ) as $db ) {
foreach ( $this->keys as $key ) {
$key = preg_replace( "/^$startWiki:/", "$db:", $key );
$cache->delete( $key );
}
}

return true;
}
}
9 changes: 9 additions & 0 deletions maintenance/rebuildVersionCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
use Maintenance;
use MediaWiki\Config\HashConfig;
use MediaWiki\MainConfigNames;
use MediaWiki\WikiMap\WikiMap;
use Miraheze\MirahezeMagic\Jobs\ClearGitInfoCache;

/**
* Maintenance script to rebuild the version cache.
Expand Down Expand Up @@ -104,6 +106,9 @@ public function execute() {
);
}

// This will be used in the job
$keys = [];

$version = $this->getOption( 'version' );
foreach ( $extensionCredits as $extension => $extensionData ) {
if ( isset( $extensionData['path'] ) ) {
Expand All @@ -117,10 +122,14 @@ public function execute() {
$memcKey = $cache->makeKey(
'specialversion-ext-version-text', str_replace( $baseDirectory, '/srv/mediawiki/' . $version, $extensionData['path'] ), $coreId
);
$keys[] = $memcKey;

$cache->delete( $memcKey );
}
}

$job = new ClearGitInfoCache( [ 'startWiki' => WikiMap::getCurrentWikiId(), 'keys' => $keys ] );
$this->getServiceContainer()->getJobQueueGroup()->push( $job );
}

private function getGitInfo( string $directory ): ?array {
Expand Down