-
-
Notifications
You must be signed in to change notification settings - Fork 48
Implement fast track deletion for unused wikis #605
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
base: main
Are you sure you want to change the base?
Changes from 14 commits
e474dd3
a4c1e76
1a05ce3
af8bc38
e01fff2
b6baf70
dc29c1c
84f71d4
2fa301f
b826b1a
45a7c37
b82de09
8f0edcf
2cef205
37499fd
b5b4bcd
dd36d69
f6d7335
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,10 @@ public function execute(): void { | |
| } | ||
|
|
||
| public function getTimestamp(): int { | ||
| $defaultActor = $this->getServiceContainer()->getUserFactory() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should have a test case in CheckLastWikiActivityTest to make sure properly excludes MediaWiki default edits. |
||
| ->newFromName( 'MediaWiki default' ) | ||
| ->getActorId(); | ||
|
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusiveImprovement to exclude MediaWiki default actor from activity checks This change adds logic to filter out log entries from the MediaWiki default actor, ensuring that only meaningful user activities are counted when determining wiki activity. A test case in CheckLastWikiActivityTest would be valuable to verify that this properly excludes MediaWiki default edits, as mentioned in a previous review. 🏁 Script executed: #!/bin/bash
# Check if any test exists for this functionality
rg -t php "MediaWiki default" tests/phpunitLength of output: 45 Action Required: Add a test to verify MediaWiki default actor exclusion The logic in |
||
|
|
||
| $dbr = $this->getDB( DB_REPLICA ); | ||
|
|
||
| // Get the latest revision timestamp | ||
|
|
@@ -37,6 +41,7 @@ public function getTimestamp(): int { | |
| ->where( [ | ||
| $dbr->expr( 'log_type', '!=', 'renameuser' ), | ||
| $dbr->expr( 'log_type', '!=', 'newusers' ), | ||
| $dbr->expr( 'log_actor', '!=', $defaultActor ), | ||
| ] ) | ||
| ->orderBy( 'log_timestamp', SelectQueryBuilder::SORT_DESC ) | ||
| ->limit( 1 ) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also needs tests in ManageInactiveWikisTest but I can probably put some work into doing that at some point. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| namespace Miraheze\CreateWiki\Maintenance; | ||
|
|
||
| use MediaWiki\Maintenance\Maintenance; | ||
| use MediaWiki\Config\ConfigException; | ||
| use Miraheze\CreateWiki\ConfigNames; | ||
| use Miraheze\CreateWiki\Services\RemoteWikiFactory; | ||
|
|
||
|
|
@@ -32,6 +33,8 @@ public function execute(): void { | |
| $this->fatalError( 'Enable $wgCreateWikiEnableManageInactiveWikis to run this script.' ); | ||
| } | ||
|
|
||
| $inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['no-edits']['inactive']; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we hardcode no-edits here? I'm uncertain about that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance wise, the check this is used in is to tell if it's worth doing more processing. Using the function to get the proper check would mean that code(querying the database) runs for every wiki even if they're active, while if we leave it here, |
||
|
|
||
| $databaseUtils = $this->getServiceContainer()->get( 'CreateWikiDatabaseUtils' ); | ||
| $remoteWikiFactory = $this->getServiceContainer()->get( 'RemoteWikiFactory' ); | ||
|
|
||
|
|
@@ -49,8 +52,6 @@ public function execute(): void { | |
|
|
||
| foreach ( $wikis as $wiki ) { | ||
| $remoteWiki = $remoteWikiFactory->newInstance( $wiki ); | ||
| $inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['inactive']; | ||
|
|
||
| $remoteWiki->disableResetDatabaseLists(); | ||
|
|
||
| // Check if the wiki is inactive based on creation date | ||
|
|
@@ -68,18 +69,33 @@ 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->createChild( CheckLastWikiActivity::class ); | ||
| '@phan-var CheckLastWikiActivity $activity'; | ||
|
|
||
| $activity->setDB( $this->getDB( DB_PRIMARY, [], $dbname ) ); | ||
| $lastActivityTimestamp = $activity->getTimestamp(); | ||
|
|
||
| $stateConfig = $this->getConfig()->get( ConfigNames::StateDays ); | ||
|
|
||
| if ( !isset( $stateConfig['default'] ) ) { | ||
| throw new ConfigException( | ||
| 'Default state config not found. Please check your configuration.' | ||
| ); | ||
| } | ||
| if ( !isset( $stateConfig['no-edits'] ) ) { | ||
| $stateConfig['no-edits'] = $stateConfig['default']; | ||
| $this->output( | ||
| 'No edits state config not found, using default instead.' | ||
pixDeVl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
| $track = $lastActivityTimestamp !== 0 ? 'default' : 'no-edits'; | ||
|
|
||
| $inactiveDays = (int)$stateConfig[$track]['inactive']; | ||
| $closeDays = (int)$stateConfig[$track]['closed']; | ||
| $removeDays = (int)$stateConfig[$track]['removed']; | ||
| $canWrite = $this->hasOption( 'write' ); | ||
pixDeVl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // If the wiki is still active, mark it as active | ||
| if ( $lastActivityTimestamp > date( 'YmdHis', strtotime( "-{$inactiveDays} days" ) ) ) { | ||
| if ( $canWrite && $remoteWiki->isInactive() ) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.