mTitle = $titleTo; $this->mTable = $table; $this->mRowsPerJob = $wgUpdateRowsPerJob; $this->mRowsPerQuery = $wgUpdateRowsPerQuery; $this->mCache = $this->mTitle->getBacklinkCache(); } public function doUpdate() { # Fetch the IDs $numRows = $this->mCache->getNumLinks( $this->mTable ); if ( $numRows != 0 ) { if ( $numRows > $this->mRowsPerJob ) { $this->insertJobs(); } else { $this->invalidate(); } } wfRunHooks( 'HTMLCacheUpdate::doUpdate', array($this->mTitle) ); } protected function insertJobs() { $batches = $this->mCache->partition( $this->mTable, $this->mRowsPerJob ); if ( !$batches ) { return; } foreach ( $batches as $batch ) { $params = array( 'table' => $this->mTable, 'start' => $batch[0], 'end' => $batch[1], ); $jobs[] = new HTMLCacheUpdateJob( $this->mTitle, $params ); } Job::batchInsert( $jobs ); } /** * Invalidate a set of pages, right now */ public function invalidate( $startId = false, $endId = false ) { global $wgUseFileCache, $wgUseSquid; $titleArray = $this->mCache->getLinks( $this->mTable, $startId, $endId ); if ( $titleArray->count() == 0 ) { return; } $dbw = wfGetDB( DB_MASTER ); $timestamp = $dbw->timestamp(); # Get all IDs in this query into an array $ids = array(); foreach ( $titleArray as $title ) { $ids[] = $title->getArticleID(); } # Update page_touched $dbw->update( 'page', array( 'page_touched' => $timestamp ), array( 'page_id IN (' . $dbw->makeList( $ids ) . ')' ), __METHOD__ ); # Update squid if ( $wgUseSquid ) { $u = SquidUpdate::newFromTitles( $titleArray ); $u->doUpdate(); } # Update file cache if ( $wgUseFileCache ) { foreach ( $titleArray as $title ) { HTMLFileCache::clearFileCache( $title ); } } } } /** * Job wrapper for HTMLCacheUpdate. Gets run whenever a related * job gets called from the queue. * * @ingroup JobQueue */ class HTMLCacheUpdateJob extends Job { var $table, $start, $end; /** * Construct a job * @param Title $title The title linked to * @param array $params Job parameters (table, start and end page_ids) * @param integer $id job_id */ function __construct( $title, $params, $id = 0 ) { parent::__construct( 'htmlCacheUpdate', $title, $params, $id ); $this->table = $params['table']; $this->start = $params['start']; $this->end = $params['end']; } public function run() { $update = new HTMLCacheUpdate( $this->title, $this->table ); $update->invalidate( $this->start, $this->end ); return true; } }