Hashar has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310547

Change subject: CdnCacheUpdate merge now drop duplicate URLs
......................................................................

CdnCacheUpdate merge now drop duplicate URLs

I noticed the list of URLs to purge having duplicates. The reason is
array_merge() on array having numeric key appends instead of merging
(unlike the + operator which does the proper merging).

Add array_unique() in the merge() method.
Adjust test to do a lot more assertions:
* no dupe (easy with array_count_values())
* only one CdnCacheUpdate job
* the deferred update match the merged job

purge() does have an array_unique(), so it is merely cosmetic.

Change-Id: I646ac01b6f91fb87ecd38c9a17f60ae69187104c
---
M includes/deferred/CdnCacheUpdate.php
M tests/phpunit/includes/deferred/CdnCacheUpdateTest.php
2 files changed, 18 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/47/310547/1

diff --git a/includes/deferred/CdnCacheUpdate.php 
b/includes/deferred/CdnCacheUpdate.php
index 470086a..d2b1076 100644
--- a/includes/deferred/CdnCacheUpdate.php
+++ b/includes/deferred/CdnCacheUpdate.php
@@ -43,7 +43,8 @@
                /** @var CdnCacheUpdate $update */
                Assert::parameterType( __CLASS__, $update, '$update' );
 
-               $this->urls = array_merge( $this->urls, $update->urls );
+               $this->urls = array_unique(
+                       array_merge( $this->urls, $update->urls ) );
        }
 
        /**
diff --git a/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php 
b/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php
index b96ec08..42ce925 100644
--- a/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php
+++ b/tests/phpunit/includes/deferred/CdnCacheUpdateTest.php
@@ -19,7 +19,22 @@
                $update2 = new CdnCacheUpdate( $urls2 );
                DeferredUpdates::addUpdate( $update2 );
 
+               $deferred = TestingAccessWrapper::newFromClass( 
'DeferredUpdates' );
+               $this->assertEquals( 1, count( 
$deferred->postSendUpdates['CdnCacheUpdate'] ),
+                       'CdnCacheUpdate deferred updates are merged' );
+
                $wrapper = TestingAccessWrapper::newFromObject( $update1 );
-               $this->assertEquals( array_merge( $urls1, $urls2 ), 
$wrapper->urls );
+               $frequencies = array_count_values( $wrapper->urls );
+               $dupes = array_filter( $frequencies, function( $f ) {
+                       return $f !== 1;
+               } );
+               $this->assertEquals( [], $dupes, "There must be no duplicate 
URLs" );
+               $this->assertEquals( array_unique( array_merge( $urls1, $urls2 
) ), $wrapper->urls );
+
+               $this->assertEquals( 0, count( $deferred->preSendUpdates ),
+                       'CdnCacheUpdate is not in preSendUpdates' );
+               $this->assertEquals( $update1, 
$deferred->postSendUpdates['CdnCacheUpdate'],
+                       'The first update is in the deferred queue' );
+
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/310547
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I646ac01b6f91fb87ecd38c9a17f60ae69187104c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <has...@free.fr>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to