Make CDN purge calls use DeferredUpdates
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 1 Dec 2015 00:05:56 +0000 (16:05 -0800)
committerKrinkle <krinklemail@gmail.com>
Fri, 4 Dec 2015 19:09:03 +0000 (19:09 +0000)
* Using addUpdate() makes sure purges are coalesced and
  de-duplicated.
* Also removed incosistent $wgUseSquid checks. If CDN caching
  is not used, then $wgSquidServers will just be empty anyway.

Bug: T119016
Change-Id: I8b448366f037f668385d252f9d68289b71d1a707

includes/Title.php
includes/filerepo/file/LocalFile.php
includes/jobqueue/jobs/HTMLCacheUpdateJob.php
includes/page/WikiPage.php
includes/revisiondelete/RevDelFileList.php

index 4b39efd..46131c1 100644 (file)
@@ -3591,12 +3591,10 @@ class Title {
         * Purge all applicable Squid URLs
         */
        public function purgeSquid() {
-               global $wgUseSquid;
-               if ( $wgUseSquid ) {
-                       $urls = $this->getSquidURLs();
-                       $u = new SquidUpdate( $urls );
-                       $u->doUpdate();
-               }
+               DeferredUpdates::addUpdate(
+                       new SquidUpdate( $this->getSquidURLs() ),
+                       DeferredUpdates::PRESEND
+               );
        }
 
        /**
index c2bbb4e..dcc8741 100644 (file)
@@ -879,7 +879,10 @@ class LocalFile extends File {
                $this->purgeThumbnails( $options );
 
                // Purge squid cache for this file
-               SquidUpdate::purge( array( $this->getURL() ) );
+               DeferredUpdates::addUpdate(
+                       new SquidUpdate( array( $this->getUrl() ) ),
+                       DeferredUpdates::PRESEND
+               );
        }
 
        /**
@@ -887,8 +890,6 @@ class LocalFile extends File {
         * @param string $archiveName Name of the archived file
         */
        function purgeOldThumbnails( $archiveName ) {
-               global $wgUseSquid;
-
                // Get a list of old thumbnails and URLs
                $files = $this->getThumbnails( $archiveName );
 
@@ -899,14 +900,11 @@ class LocalFile extends File {
                $this->purgeThumbList( $dir, $files );
 
                // Purge the squid
-               if ( $wgUseSquid ) {
-                       $urls = array();
-                       foreach ( $files as $file ) {
-                               $urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
-                       }
-                       SquidUpdate::purge( $urls );
+               $urls = array();
+               foreach ( $files as $file ) {
+                       $urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
                }
-
+               DeferredUpdates::addUpdate( new SquidUpdate( $urls ), DeferredUpdates::PRESEND );
        }
 
        /**
@@ -914,18 +912,14 @@ class LocalFile extends File {
         * @param array $options
         */
        public function purgeThumbnails( $options = array() ) {
-               global $wgUseSquid;
-
                // Delete thumbnails
                $files = $this->getThumbnails();
                // Always purge all files from squid regardless of handler filters
                $urls = array();
-               if ( $wgUseSquid ) {
-                       foreach ( $files as $file ) {
-                               $urls[] = $this->getThumbUrl( $file );
-                       }
-                       array_shift( $urls ); // don't purge directory
+               foreach ( $files as $file ) {
+                       $urls[] = $this->getThumbUrl( $file );
                }
+               array_shift( $urls ); // don't purge directory
 
                // Give media handler a chance to filter the file purge list
                if ( !empty( $options['forThumbRefresh'] ) ) {
@@ -942,10 +936,7 @@ class LocalFile extends File {
                $this->purgeThumbList( $dir, $files );
 
                // Purge the squid
-               if ( $wgUseSquid ) {
-                       SquidUpdate::purge( $urls );
-               }
-
+               DeferredUpdates::addUpdate( new SquidUpdate( $urls ), DeferredUpdates::PRESEND );
        }
 
        /**
@@ -1444,7 +1435,10 @@ class LocalFile extends File {
                                # Delete old thumbnails
                                $that->purgeThumbnails();
                                # Remove the old file from the squid cache
-                               SquidUpdate::purge( array( $that->getURL() ) );
+                               DeferredUpdates::addUpdate(
+                                       new SquidUpdate( array( $that->getUrl() ) ),
+                                       DeferredUpdates::PRESEND
+                               );
                        } else {
                                # Update backlink pages pointing to this title if created
                                LinksUpdate::queueRecursiveJobsForTable( $that->getTitle(), 'imagelinks' );
@@ -1631,24 +1625,20 @@ class LocalFile extends File {
                $that = $this;
                $this->getRepo()->getMasterDB()->onTransactionIdle(
                        function () use ( $that, $archiveNames ) {
-                               global $wgUseSquid;
-
                                $that->purgeEverything();
                                foreach ( $archiveNames as $archiveName ) {
                                        $that->purgeOldThumbnails( $archiveName );
                                }
-
-                               if ( $wgUseSquid ) {
-                                       // Purge the squid
-                                       $purgeUrls = array();
-                                       foreach ( $archiveNames as $archiveName ) {
-                                               $purgeUrls[] = $that->getArchiveUrl( $archiveName );
-                                       }
-                                       SquidUpdate::purge( $purgeUrls );
-                               }
                        }
                );
 
+               // Purge the squid
+               $purgeUrls = array();
+               foreach ( $archiveNames as $archiveName ) {
+                       $purgeUrls[] = $this->getArchiveUrl( $archiveName );
+               }
+               DeferredUpdates::addUpdate( new SquidUpdate( $purgeUrls ), DeferredUpdates::PRESEND );
+
                return $status;
        }
 
@@ -1668,7 +1658,6 @@ class LocalFile extends File {
         * @return FileRepoStatus
         */
        function deleteOld( $archiveName, $reason, $suppress = false, $user = null ) {
-               global $wgUseSquid;
                if ( $this->getRepo()->getReadOnlyReason() !== false ) {
                        return $this->readOnlyFatalStatus();
                }
@@ -1685,10 +1674,10 @@ class LocalFile extends File {
                        $this->purgeDescription();
                }
 
-               if ( $wgUseSquid ) {
-                       // Purge the squid
-                       SquidUpdate::purge( array( $this->getArchiveUrl( $archiveName ) ) );
-               }
+               DeferredUpdates::addUpdate(
+                       new SquidUpdate( array( $this->getArchiveUrl( $archiveName ) ) ),
+                       DeferredUpdates::PRESEND
+               );
 
                return $status;
        }
index 6b1a1e3..27b6fd7 100644 (file)
@@ -77,7 +77,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 );
@@ -123,10 +123,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 ) {
index 5a6511c..6071d9b 100644 (file)
@@ -1160,16 +1160,16 @@ class WikiPage implements Page, IDBAccessObject {
 
                $title = $this->mTitle;
                wfGetDB( DB_MASTER )->onTransactionIdle( function() use ( $title ) {
-                       global $wgUseSquid;
                        // Invalidate the cache in auto-commit mode
                        $title->invalidateCache();
-                       if ( $wgUseSquid ) {
-                               // Send purge now that page_touched update was committed above
-                               $update = new SquidUpdate( $title->getSquidURLs() );
-                               $update->doUpdate();
-                       }
                } );
 
+               // Send purge after above page_touched update was committed
+               DeferredUpdates::addUpdate(
+                       new SquidUpdate( $title->getSquidURLs() ),
+                       DeferredUpdates::PRESEND
+               );
+
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                        // @todo move this logic to MessageCache
                        if ( $this->exists() ) {
index 2295eaa..e5f32d2 100644 (file)
@@ -108,16 +108,18 @@ class RevDelFileList extends RevDelList {
                $file = wfLocalFile( $this->title );
                $file->purgeCache();
                $file->purgeDescription();
+
+               // Purge full images from cache
                $purgeUrls = array();
                foreach ( $this->ids as $timestamp ) {
                        $archiveName = $timestamp . '!' . $this->title->getDBkey();
                        $file->purgeOldThumbnails( $archiveName );
                        $purgeUrls[] = $file->getArchiveUrl( $archiveName );
                }
-               if ( $this->getConfig()->get( 'UseSquid' ) ) {
-                       // purge full images from cache
-                       SquidUpdate::purge( $purgeUrls );
-               }
+               DeferredUpdates::addUpdate(
+                       new SquidUpdate( $purgeUrls ),
+                       DeferredUpdates::PRESEND
+               );
 
                return Status::newGood();
        }