Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fast track deletion for unused wikis #605

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
16 changes: 12 additions & 4 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,18 @@
"CreateWikiStateDays": {
"description": "Array. Integer values in days when a wiki is deemed inactive, closed, removed (hidden) and deleted. Number of days passed since last change - not from initial inactivity.",
"value": {
"inactive": 45,
"closed": 15,
"removed": 120,
"deleted": 7
"no-edits": {
"inactive": 15,
"closed": 30,
"removed": 0,
"deleted": 0
},
"default": {
"inactive": 45,
"closed": 15,
"removed": 120,
"deleted": 7
}
}
},
"CreateWikiSubdomain": {
Expand Down
9 changes: 9 additions & 0 deletions maintenance/checkLastWikiActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ public function execute(): void {
}

public function getTimestamp(): int {
$defaultActor = $this->getServiceContainer()
->getUserFactory()
->newFromName( 'MediaWiki default' )
->getActorId();

$dbr = $this->getDB( DB_REPLICA );

// Get the latest revision timestamp
$revTimestamp = $dbr->newSelectQueryBuilder()
->select( 'MAX(rev_timestamp)' )
->from( 'revision' )
->where( [
$dbr->expr( 'rev_actor', '!=', $defaultActor ),
] )
->caller( __METHOD__ )
->fetchField();

Expand All @@ -43,6 +51,7 @@ public function getTimestamp(): int {
->where( [
$dbr->expr( 'log_type', '!=', 'renameuser' ),
$dbr->expr( 'log_type', '!=', 'newusers' ),
$dbr->expr( 'log_actor', '!=', $defaultActor ),
] )
->caller( __METHOD__ )
->fetchField();
Expand Down
14 changes: 8 additions & 6 deletions maintenance/manageInactiveWikis.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function execute(): void {
foreach ( $res as $row ) {
$dbName = $row->wiki_dbname;
$remoteWiki = $remoteWikiFactory->newInstance( $dbName );
$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['inactive'];
$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['default']['inactive'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be no-edits?

Copy link
Author

Choose a reason for hiding this comment

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

I think so? I'll do some thinking, but also need to look to make sure we're not breaking any previously implemented assumptions about the state from when there was only one track.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the no_edits_inactivity < default_inactivity, but we only do checking for when it's default, then the no edits stuff won't trigger, right?

Copy link
Author

Choose a reason for hiding this comment

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

Updated to no-edits, but we should take a look to see if that doesn't break and assumptions and cause it to early close any wikis it shouldn't. A bit late for me to be doing a thoughtful look right now though.

Copy link
Contributor

Choose a reason for hiding this comment

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


// Check if the wiki is inactive based on creation date
if ( $remoteWiki->getCreationDate() < date( 'YmdHis', strtotime( "-{$inactiveDays} days" ) ) ) {
Expand All @@ -64,11 +64,6 @@ private function checkLastActivity(
string $dbName,
RemoteWikiFactory $remoteWiki
): bool {
$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['inactive'];
$closeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['closed'];
$removeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['removed'];
$canWrite = $this->hasOption( 'write' );

/** @var CheckLastWikiActivity $activity */
$activity = $this->runChild(
CheckLastWikiActivity::class,
Expand All @@ -82,6 +77,13 @@ private function checkLastActivity(

$lastActivityTimestamp = $activity->getTimestamp();

$track = ( $lastActivityTimestamp !== 0 ) ? 'default': 'no-edits'
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary parentheses and syntax error. (missing semicolon)

$track = $lastActivityTimestamp ? 'default' : 'no-edits';

Also we need some validation here if configured incorrectly. If no-edits is not set at all, always use default, if neither is not set use the old behavior and add null checks with ??. Maybe this should be split to seperate method? I guess we could just throw ConfigException if configured incorrectly also...


$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )[$track]['inactive'];
$closeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )[$track]['closed'];
$removeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )[$track]['removed'];
$canWrite = $this->hasOption( 'write' );

// If the wiki is still active, mark it as active
if ( $lastActivityTimestamp > date( 'YmdHis', strtotime( "-{$inactiveDays} days" ) ) ) {
if ( $canWrite && $remoteWiki->isInactive() ) {
Expand Down
Loading