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
4 changes: 4 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@
"description": "String. The main part of subdomains, e.g. wiki.example.org, example.org is the main part.",
"value": ""
},
"CreateWikiTrackDatabaseListMetrics": {
"description": "Boolean. Whether to track metrics related to the (re)generation of database lists.",
"value": false
},
"CreateWikiUseClosedWikis": {
"description": "Boolean. Whether to implement front end logic for closing wikis.",
"value": false
Expand Down
2 changes: 2 additions & 0 deletions includes/ConfigNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ConfigNames {

public const EmailNotifications = 'CreateWikiEmailNotifications';

public const TrackDatabaseListMetrics = 'CreateWikiTrackDatabaseListMetrics';
Copy link
Member

Choose a reason for hiding this comment

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

Alphabetical order please.


public const EnableManageInactiveWikis = 'CreateWikiEnableManageInactiveWikis';

public const EnableRESTAPI = 'CreateWikiEnableRESTAPI';
Expand Down
2 changes: 1 addition & 1 deletion includes/Helpers/RemoteWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function commit(): void {
}

if ( $this->resetDatabaseLists ) {
$this->dataStore->resetDatabaseLists( isNewChanges: true );
$this->dataStore->resetDatabaseLists( isNewChanges: true, caller: __METHOD__ );
}

$this->hookRunner->onCreateWikiRemoteWikiCommit( $this->dbname );
Expand Down
1 change: 1 addition & 0 deletions includes/ServiceWiring.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'CreateWikiDataStore' => static function ( MediaWikiServices $services ): CreateWikiDataStore {
return new CreateWikiDataStore(
$services->getObjectCacheFactory(),
$services->getStatsFactory(),
$services->get( 'CreateWikiDatabaseUtils' ),
$services->get( 'CreateWikiHookRunner' ),
new ServiceOptions(
Expand Down
27 changes: 24 additions & 3 deletions includes/Services/CreateWikiDataStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Wikimedia\ObjectCache\BagOStuff;
use Wikimedia\Rdbms\IReadableDatabase;
use Wikimedia\StaticArrayWriter;
use Wikimedia\Stats\StatsFactory;
use function array_keys;
use function file_put_contents;
use function function_exists;
Expand All @@ -28,6 +29,7 @@ class CreateWikiDataStore {
public const CONSTRUCTOR_OPTIONS = [
ConfigNames::CacheDirectory,
ConfigNames::CacheType,
ConfigNames::TrackDatabaseListMetrics,
MainConfigNames::CacheDirectory,
MainConfigNames::LocalDatabases,
];
Expand All @@ -41,9 +43,11 @@ class CreateWikiDataStore {
private readonly string $cacheDir;
private int $timestamp;
private int $localServerTimestamp;
private readonly bool $trackDatabaseListMetrics;

public function __construct(
ObjectCacheFactory $objectCacheFactory,
private readonly StatsFactory $statsFactory,
private readonly CreateWikiDatabaseUtils $databaseUtils,
private readonly CreateWikiHookRunner $hookRunner,
private readonly ServiceOptions $options
Expand All @@ -64,6 +68,8 @@ public function __construct(
$this->localServerTimestamp = (int)$this->localServerCache->get(
$this->localServerCache->makeGlobalKey( self::CACHE_KEY, 'databases-local' )
);

$this->trackDatabaseListMetrics = $this->options->get( ConfigNames::TrackDatabaseListMetrics );
Copy link
Member

Choose a reason for hiding this comment

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

Don't really need to do a property here and just use the option directly since its only used once.

}

/**
Expand All @@ -73,7 +79,7 @@ public function __construct(
*/
public function syncCache(): void {
if ( !$this->timestamp ) {
$this->resetDatabaseLists( isNewChanges: true );
$this->resetDatabaseLists( isNewChanges: true, caller: __METHOD__ );
return;
}

Expand All @@ -86,7 +92,7 @@ public function syncCache(): void {
// Only regenerate if localServerTimestamp is smaller than timestamp so multiple processes on the
// same server don't try regenerating the dblists at the same time.
if ( ( $mtime === 0 || $mtime < $this->timestamp ) && $this->localServerTimestamp < $this->timestamp ) {
$this->resetDatabaseLists( isNewChanges: false );
$this->resetDatabaseLists( isNewChanges: false, caller: __METHOD__ );
}
}

Expand All @@ -105,7 +111,20 @@ public function getAllDatabases(): array {
* the updated list to a PHP file within the cache directory. It also updates the
* modification time (mtime) and stores it in the cache for future reference.
*/
public function resetDatabaseLists( bool $isNewChanges ): void {
// @phan-suppress-next-line PhanDisallowedOptionalMethodParameter
public function resetDatabaseLists( bool $isNewChanges, ?string $caller = null ): void {
Copy link
Member

Choose a reason for hiding this comment

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

No optional params please. Explicitly pass empty string and check where we dont want it. Easier to read at call sites as well that way. Though really it should just always be passed as __METHOD__ anyway, and only accept strings, then you can also avoid ?? 'unknown' which would not help at all, and there really is no reason to not pass it even if we arent using it.

$timer = null;
if ( $this->trackDatabaseListMetrics ) {
/** @phan-suppress-next-line PhanPossiblyUndeclaredMethod */
$this->statsFactory->getCounter( 'createwiki_dblist_generation_total' )
->setLabel( 'cause', $caller ?? 'unknown' )
->setLabel( 'new_changes', $isNewChanges ? 'Yes' : 'No' )
->increment();

$timer = $this->statsFactory->getTiming( 'createwiki_dblist_generation_seconds' )
->start();
}

$mtime = time();
$this->localServerCache->set(
$this->localServerCache->makeGlobalKey( self::CACHE_KEY, 'databases-local' ),
Expand All @@ -132,6 +151,7 @@ public function resetDatabaseLists( bool $isNewChanges ): void {
$this->writeToFile( $name, $list );
}

$timer?->stop();
return;
}

Expand Down Expand Up @@ -171,6 +191,7 @@ public function resetDatabaseLists( bool $isNewChanges ): void {
];

$this->writeToFile( 'databases', $list );
$timer?->stop();
}

/**
Expand Down
9 changes: 5 additions & 4 deletions includes/Services/WikiManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ private function doAfterCreate(

$this->hookRunner->onCreateWikiCreation( $this->dbname, $private );

$method = __METHOD__;
DeferredUpdates::addCallableUpdate(
function () use ( $requester, $extra ) {
$this->dataStore->resetDatabaseLists( isNewChanges: true );
function () use ( $requester, $extra, $method ) {
$this->dataStore->resetDatabaseLists( isNewChanges: true, caller: $method );
$limits = [ 'memory' => 0, 'filesize' => 0, 'time' => 0, 'walltime' => 0 ];

Shell::makeScriptCommand(
Expand Down Expand Up @@ -383,7 +384,7 @@ public function delete( bool $force ): ?string {
->execute();
}

$this->dataStore->resetDatabaseLists( isNewChanges: true );
$this->dataStore->resetDatabaseLists( isNewChanges: true, caller: __METHOD__ );
$this->hookRunner->onCreateWikiDeletion( $this->cwdb, $this->dbname );

return null;
Expand Down Expand Up @@ -417,7 +418,7 @@ public function rename( string $newDatabaseName ): ?string {
->execute();
}

$this->dataStore->resetDatabaseLists( isNewChanges: true );
$this->dataStore->resetDatabaseLists( isNewChanges: true, caller: __METHOD__ );
$this->hookRunner->onCreateWikiRename( $this->cwdb, $this->dbname, $newDatabaseName );

return null;
Expand Down
2 changes: 1 addition & 1 deletion maintenance/ManageInactiveWikis.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function execute(): void {
}
}

$this->dataStore->resetDatabaseLists( isNewChanges: true );
$this->dataStore->resetDatabaseLists( isNewChanges: true, caller: __METHOD__ );
}

private function checkLastActivity(
Expand Down
Loading