00001 <?php 00002 00026 class HTMLCacheUpdate 00027 { 00028 public $mTitle, $mTable, $mPrefix; 00029 public $mRowsPerJob, $mRowsPerQuery; 00030 00031 function __construct( $titleTo, $table ) { 00032 global $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery; 00033 00034 $this->mTitle = $titleTo; 00035 $this->mTable = $table; 00036 $this->mRowsPerJob = $wgUpdateRowsPerJob; 00037 $this->mRowsPerQuery = $wgUpdateRowsPerQuery; 00038 $this->mCache = $this->mTitle->getBacklinkCache(); 00039 } 00040 00041 public function doUpdate() { 00042 # Fetch the IDs 00043 $numRows = $this->mCache->getNumLinks( $this->mTable ); 00044 00045 if ( $numRows != 0 ) { 00046 if ( $numRows > $this->mRowsPerJob ) { 00047 $this->insertJobs(); 00048 } else { 00049 $this->invalidate(); 00050 } 00051 } 00052 wfRunHooks( 'HTMLCacheUpdate::doUpdate', array($this->mTitle) ); 00053 } 00054 00055 protected function insertJobs() { 00056 $batches = $this->mCache->partition( $this->mTable, $this->mRowsPerJob ); 00057 if ( !$batches ) { 00058 return; 00059 } 00060 foreach ( $batches as $batch ) { 00061 $params = array( 00062 'table' => $this->mTable, 00063 'start' => $batch[0], 00064 'end' => $batch[1], 00065 ); 00066 $jobs[] = new HTMLCacheUpdateJob( $this->mTitle, $params ); 00067 } 00068 Job::batchInsert( $jobs ); 00069 } 00070 00071 00075 public function invalidate( $startId = false, $endId = false ) { 00076 global $wgUseFileCache, $wgUseSquid; 00077 00078 $titleArray = $this->mCache->getLinks( $this->mTable, $startId, $endId ); 00079 if ( $titleArray->count() == 0 ) { 00080 return; 00081 } 00082 00083 $dbw = wfGetDB( DB_MASTER ); 00084 $timestamp = $dbw->timestamp(); 00085 00086 # Get all IDs in this query into an array 00087 $ids = array(); 00088 foreach ( $titleArray as $title ) { 00089 $ids[] = $title->getArticleID(); 00090 } 00091 # Update page_touched 00092 $dbw->update( 'page', 00093 array( 'page_touched' => $timestamp ), 00094 array( 'page_id IN (' . $dbw->makeList( $ids ) . ')' ), 00095 __METHOD__ 00096 ); 00097 00098 # Update squid 00099 if ( $wgUseSquid ) { 00100 $u = SquidUpdate::newFromTitles( $titleArray ); 00101 $u->doUpdate(); 00102 } 00103 00104 # Update file cache 00105 if ( $wgUseFileCache ) { 00106 foreach ( $titleArray as $title ) { 00107 HTMLFileCache::clearFileCache( $title ); 00108 } 00109 } 00110 } 00111 } 00112 00119 class HTMLCacheUpdateJob extends Job { 00120 var $table, $start, $end; 00121 00128 function __construct( $title, $params, $id = 0 ) { 00129 parent::__construct( 'htmlCacheUpdate', $title, $params, $id ); 00130 $this->table = $params['table']; 00131 $this->start = $params['start']; 00132 $this->end = $params['end']; 00133 } 00134 00135 public function run() { 00136 $update = new HTMLCacheUpdate( $this->title, $this->table ); 00137 $update->invalidate( $this->start, $this->end ); 00138 return true; 00139 } 00140 }