diff options
author | Brad Jorsch <bjorsch@wikimedia.org> | 2020-03-17 17:15:58 -0400 |
---|---|---|
committer | Brad Jorsch <bjorsch@wikimedia.org> | 2020-03-19 09:56:19 -0400 |
commit | d83e00cb92f2c850dfe8ad7f31c65f8db78e47b7 (patch) | |
tree | 6abe8de4b2ea3e6d4d185712bd6f9571e407b039 /includes/deferred/CdnCacheUpdate.php | |
parent | 3357fbba78795c26ee57c5ae91d005c420602f97 (diff) | |
download | mediawikicore-d83e00cb92f2c850dfe8ad7f31c65f8db78e47b7.tar.gz mediawikicore-d83e00cb92f2c850dfe8ad7f31c65f8db78e47b7.zip |
CdnCacheUpdate: Accept Titles in addition to strings
The class was already documented as "given a list of URLs or Title
instances", this makes that work.
Title objects will have ->getCdnUrls() called when the update is
resolved, which avoids problems like those encountered in T240083 where
that was being called too early.
Bug: T240083
Change-Id: I30b29a7359a8f393fb19ffc199211a421d3ea4d9
Diffstat (limited to 'includes/deferred/CdnCacheUpdate.php')
-rw-r--r-- | includes/deferred/CdnCacheUpdate.php | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/includes/deferred/CdnCacheUpdate.php b/includes/deferred/CdnCacheUpdate.php index afde8e17158a..0bf8dc771033 100644 --- a/includes/deferred/CdnCacheUpdate.php +++ b/includes/deferred/CdnCacheUpdate.php @@ -28,11 +28,11 @@ use Wikimedia\Assert\Assert; * @ingroup Cache */ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate { - /** @var string[] Collection of URLs to purge */ + /** @var (string|Title)[] Collection of URLs or Titles to purge */ private $urls = []; /** - * @param string[] $urlArr Collection of URLs to purge + * @param (string|Title)[] $urlArr Collection of URLs or Titles to purge */ public function __construct( array $urlArr ) { $this->urls = $urlArr; @@ -54,13 +54,7 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate { * @return CdnCacheUpdate */ public static function newFromTitles( $titles, $urlArr = [] ) { - ( new LinkBatch( $titles ) )->execute(); - /** @var Title $title */ - foreach ( $titles as $title ) { - $urlArr = array_merge( $urlArr, $title->getCdnUrls() ); - } - - return new CdnCacheUpdate( $urlArr ); + return new CdnCacheUpdate( array_merge( $titles, $urlArr ) ); } /** @@ -69,11 +63,29 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate { public function doUpdate() { global $wgCdnReboundPurgeDelay; - self::purge( $this->urls ); + $urls = []; + $titles = []; + foreach ( $this->urls as $u ) { + if ( $u instanceof Title ) { + $titles[] = $u; + } else { + $urls[] = $u; + } + } + + if ( $titles ) { + ( new LinkBatch( $titles ) )->execute(); + /** @var Title $title */ + foreach ( $titles as $title ) { + $urls = array_merge( $urls, $title->getCdnUrls() ); + } + } + + self::purge( $urls ); if ( $wgCdnReboundPurgeDelay > 0 ) { JobQueueGroup::singleton()->lazyPush( new CdnPurgeJob( [ - 'urls' => $this->urls, + 'urls' => $urls, 'jobReleaseTimestamp' => time() + $wgCdnReboundPurgeDelay ] ) ); } |