Skip to content

Commit

Permalink
Improvements to maintenance script and fix job
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Dec 16, 2023
1 parent d291981 commit 645b1bb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## ChangeLog for RottenLinks

### 2.0.1 (16-12-2023)
* Add `requireExtension` to updateExternalLinks.
* Remove unnecessary object cache from being added in updateExternalLinks.
* Prevent duplicate entries from being added to rottenlinks table in updateExternalLinks.
* Fix table name used in RottenLinksJob.

### 2.0.0 (15-12-2023)
* Redesign RottenLinks to not depend on a maintenance script
* Changes how we count page usage on RottenLinks special page. We directly gather this from externallinks table rather then storing it separately.
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RottenLinks",
"version": "2.0.0",
"version": "2.0.1",
"author": [
"John Lewis",
"Paladox",
Expand Down
4 changes: 2 additions & 2 deletions includes/RottenLinksJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public function run() {

$rottenLinksCount = $dbw->newSelectQueryBuilder()
->select( 'rl_externallink' )
->from( 'externallinks' )
->from( 'rottenlinks' )
->where( [ 'rl_externallink' => $url ] )
->caller( __METHOD__ )
->fetchRowCount();

if ( $rottenLinksCount > 0 ) {
// Don't create duplicate entires
// Don't create duplicate entries
continue;
}

Expand Down
19 changes: 14 additions & 5 deletions maintenance/updateExternalLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Maintenance;
use MediaWiki\MediaWikiServices;
use ObjectCache;
use WikiForge\RottenLinks\RottenLinks;

$IP = getenv( 'MW_INSTALL_PATH' );
Expand All @@ -19,6 +18,8 @@ public function __construct() {
parent::__construct();

$this->addDescription( 'Updates rottenlinks database table based on externallinks table.' );

$this->requireExtension( 'RottenLinks' );
}

public function execute() {
Expand Down Expand Up @@ -72,6 +73,18 @@ public function execute() {
continue;
}

$rottenLinksCount = $dbw->newSelectQueryBuilder()
->select( 'rl_externallink' )
->from( 'rottenlinks' )
->where( [ 'rl_externallink' => $url ] )
->caller( __METHOD__ )
->fetchRowCount();

if ( $rottenLinksCount > 0 ) {
// Don't create duplicate entries
continue;
}

$resp = RottenLinks::getResponse( $url );
$pagecount = count( $pages );

Expand All @@ -88,10 +101,6 @@ public function execute() {

$time = time() - $time;

$cache = ObjectCache::getLocalClusterInstance();
$cache->set( $cache->makeKey( 'RottenLinks', 'lastRun' ), $dbw->timestamp() );
$cache->set( $cache->makeKey( 'RottenLinks', 'runTime' ), $time );

$this->output( "Script took {$time} seconds.\n" );
}

Expand Down

0 comments on commit 645b1bb

Please sign in to comment.