Merge "tests: Remove unused TableCleanupTest class"
[lhc/web/wiklou.git] / includes / jobqueue / jobs / HTMLCacheUpdateJob.php
index a9010c2..ae35e30 100644 (file)
@@ -29,7 +29,7 @@
  *   - a) Recursive jobs to purge caches for backlink pages for a given title.
  *        These jobs have (recursive:true,table:<table>) set.
  *   - b) Jobs to purge caches for a set of titles (the job title is ignored).
- *           These jobs have (pages:(<page ID>:(<namespace>,<title>),...) set.
+ *        These jobs have (pages:(<page ID>:(<namespace>,<title>),...) set.
  *
  * @ingroup JobQueue
  */
@@ -40,6 +40,23 @@ class HTMLCacheUpdateJob extends Job {
                $this->removeDuplicates = ( !isset( $params['range'] ) && !isset( $params['pages'] ) );
        }
 
+       /**
+        * @param Title $title Title to purge backlink pages from
+        * @param string $table Backlink table name
+        * @return HTMLCacheUpdateJob
+        */
+       public static function newForBacklinks( Title $title, $table ) {
+               return new self(
+                       $title,
+                       array(
+                               'table' => $table,
+                               'recursive' => true
+                       ) + Job::newRootJobParams( // "overall" refresh links job info
+                               "htmlCacheUpdate:{$table}:{$title->getPrefixedText()}"
+                       )
+               );
+       }
+
        function run() {
                global $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery;
 
@@ -77,7 +94,7 @@ class HTMLCacheUpdateJob extends Job {
         * @param array $pages Map of (page ID => (namespace, DB key)) entries
         */
        protected function invalidateTitles( array $pages ) {
-               global $wgUpdateRowsPerQuery, $wgUseFileCache, $wgUseSquid;
+               global $wgUpdateRowsPerQuery, $wgUseFileCache;
 
                // Get all page IDs in this query into an array
                $pageIds = array_keys( $pages );
@@ -85,8 +102,6 @@ class HTMLCacheUpdateJob extends Job {
                        return;
                }
 
-               $dbw = wfGetDB( DB_MASTER );
-
                // The page_touched field will need to be bumped for these pages.
                // Only bump it to the present time if no "rootJobTimestamp" was known.
                // If it is known, it can be used instead, which avoids invalidating output
@@ -100,9 +115,13 @@ class HTMLCacheUpdateJob extends Job {
                        $touchTimestamp = wfTimestampNow();
                }
 
+               $dbw = wfGetDB( DB_MASTER );
                // Update page_touched (skipping pages already touched since the root job).
                // Check $wgUpdateRowsPerQuery for sanity; batch jobs are sized by that already.
                foreach ( array_chunk( $pageIds, $wgUpdateRowsPerQuery ) as $batch ) {
+                       $dbw->commit( __METHOD__, 'flush' );
+                       wfWaitForSlaves();
+
                        $dbw->update( 'page',
                                array( 'page_touched' => $dbw->timestamp( $touchTimestamp ) ),
                                array( 'page_id' => $batch,
@@ -121,10 +140,8 @@ class HTMLCacheUpdateJob extends Job {
                ) );
 
                // Update squid
-               if ( $wgUseSquid ) {
-                       $u = SquidUpdate::newFromTitles( $titleArray );
-                       $u->doUpdate();
-               }
+               $u = SquidUpdate::newFromTitles( $titleArray );
+               $u->doUpdate();
 
                // Update file cache
                if ( $wgUseFileCache ) {