Merge "Ignore noop DB transactions errors on connection loss"
[lhc/web/wiklou.git] / includes / deferred / CdnCacheUpdate.php
index 25c27e3..32f6adc 100644 (file)
@@ -29,7 +29,7 @@ use Wikimedia\Assert\Assert;
  */
 class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
        /** @var string[] Collection of URLs to purge */
-       protected $urls = array();
+       protected $urls = [];
 
        /**
         * @param string[] $urlArr Collection of URLs to purge
@@ -52,10 +52,10 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
         * @param string[] $urlArr
         * @return CdnCacheUpdate
         */
-       public static function newFromTitles( $titles, $urlArr = array() ) {
+       public static function newFromTitles( $titles, $urlArr = [] ) {
                /** @var Title $title */
                foreach ( $titles as $title ) {
-                       $urlArr = array_merge( $urlArr, $title->getSquidURLs() );
+                       $urlArr = array_merge( $urlArr, $title->getCdnUrls() );
                }
 
                return new CdnCacheUpdate( $urlArr );
@@ -67,7 +67,7 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
         * @deprecated 1.27
         */
        public static function newSimplePurge( Title $title ) {
-               return new CdnCacheUpdate( $title->getSquidURLs() );
+               return new CdnCacheUpdate( $title->getCdnUrls() );
        }
 
        /**
@@ -81,10 +81,10 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
                if ( $wgCdnReboundPurgeDelay > 0 ) {
                        JobQueueGroup::singleton()->lazyPush( new CdnPurgeJob(
                                Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ ),
-                               array(
+                               [
                                        'urls' => $this->urls,
                                        'jobReleaseTimestamp' => time() + $wgCdnReboundPurgeDelay
-                               )
+                               ]
                        ) );
                }
        }
@@ -108,10 +108,22 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
 
                wfDebugLog( 'squid', __METHOD__ . ': ' . implode( ' ', $urlArr ) );
 
+               // Reliably broadcast the purge to all edge nodes
+               $relayer = EventRelayerGroup::singleton()->getRelayer( 'cdn-url-purges' );
+               $relayer->notify(
+                       'cdn-url-purges',
+                       [
+                               'urls' => array_values( $urlArr ), // JSON array
+                               'timestamp' => microtime( true )
+                       ]
+               );
+
+               // Send lossy UDP broadcasting if enabled
                if ( $wgHTCPRouting ) {
                        self::HTCPPurge( $urlArr );
                }
 
+               // Do direct server purges if enabled (this does not scale very well)
                if ( $wgSquidServers ) {
                        // Maximum number of parallel connections per squid
                        $maxSocketsPerSquid = 8;
@@ -195,7 +207,7 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
 
                        if ( isset( $conf['host'] ) && isset( $conf['port'] ) ) {
                                // Normalize single entries
-                               $conf = array( $conf );
+                               $conf = [ $conf ];
                        }
                        foreach ( $conf as $subconf ) {
                                if ( !isset( $subconf['host'] ) || !isset( $subconf['port'] ) ) {