Each expired row has to be fetched from the user_groups table, deleted from that table and added to the user_former_groups table. Per Jaimes request, let's not do this for all rows at once but for smaller chunks and wait for replication to catch up after each chunk has been processed. In addition the function to purge the expired rows now sets a lock so that there won't be multiple concurrent runs. Also, cleaning this table up isn't urgent and thus should be done in a job and not a deferred update, so let's move it there. Bug: T176754 Change-Id: I671d4b9d09677a2f474477ba7fea33a44d6318aa
42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
|
|
class SiteStatsTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @covers SiteStats::jobs
|
|
*/
|
|
function testJobsCountGetCached() {
|
|
$this->setService( 'MainWANObjectCache',
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ) );
|
|
$cache = \MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache();
|
|
$jobq = JobQueueGroup::singleton();
|
|
|
|
// Delete jobs that might have been left behind by other tests
|
|
$jobq->get( 'htmlCacheUpdate' )->delete();
|
|
$jobq->get( 'recentChangesUpdate' )->delete();
|
|
$jobq->get( 'userGroupExpiry' )->delete();
|
|
$cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
|
|
|
|
$jobq->push( new NullJob( Title::newMainPage(), [] ) );
|
|
$this->assertEquals( 1, SiteStats::jobs(),
|
|
'A single job enqueued bumps jobscount stat to 1' );
|
|
|
|
$jobq->push( new NullJob( Title::newMainPage(), [] ) );
|
|
$this->assertEquals( 1, SiteStats::jobs(),
|
|
'SiteStats::jobs() count does not reflect addition ' .
|
|
'of a second job (cached)'
|
|
);
|
|
|
|
$jobq->get( 'null' )->delete(); // clear jobqueue
|
|
$this->assertEquals( 0, $jobq->get( 'null' )->getSize(),
|
|
'Job queue for NullJob has been cleaned' );
|
|
|
|
$cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
|
|
$this->assertEquals( 1, SiteStats::jobs(),
|
|
'jobs count is kept in process cache' );
|
|
|
|
$cache->clearProcessCache();
|
|
$this->assertEquals( 0, SiteStats::jobs() );
|
|
}
|
|
|
|
}
|