From afbff42aca049d32aec003db720ff88f204c83d2 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 30 Nov 2015 16:05:56 -0800 Subject: [PATCH] Make CDN purge calls use DeferredUpdates * 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 | 10 ++- includes/filerepo/file/LocalFile.php | 65 ++++++++----------- includes/jobqueue/jobs/HTMLCacheUpdateJob.php | 8 +-- includes/page/WikiPage.php | 12 ++-- includes/revisiondelete/RevDelFileList.php | 10 +-- 5 files changed, 46 insertions(+), 59 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 4b39efd199..46131c1da0 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 + ); } /** diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index c2bbb4eae4..dcc87412ec 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -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; } diff --git a/includes/jobqueue/jobs/HTMLCacheUpdateJob.php b/includes/jobqueue/jobs/HTMLCacheUpdateJob.php index 6b1a1e3f4b..27b6fd710c 100644 --- a/includes/jobqueue/jobs/HTMLCacheUpdateJob.php +++ b/includes/jobqueue/jobs/HTMLCacheUpdateJob.php @@ -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 ) { diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 5a6511ca8a..6071d9b9f4 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -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() ) { diff --git a/includes/revisiondelete/RevDelFileList.php b/includes/revisiondelete/RevDelFileList.php index 2295eaa106..e5f32d22db 100644 --- a/includes/revisiondelete/RevDelFileList.php +++ b/includes/revisiondelete/RevDelFileList.php @@ -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(); } -- 2.20.1