Smalyshev has uploaded a new change for review.

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

Change subject: [WIP] Add cache purging
......................................................................

[WIP] Add cache purging

Bug: T128667
Change-Id: I6c6d093f5af164e3a4df4493f3aed15d82bb9741
---
M repo/includes/LinkedData/EntityDataRequestHandler.php
M repo/includes/LinkedData/EntityDataSerializationService.php
M repo/includes/LinkedData/EntityDataUriManager.php
M repo/tests/phpunit/includes/LinkedData/EntityDataUriManagerTest.php
4 files changed, 59 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/69/275769/1

diff --git a/repo/includes/LinkedData/EntityDataRequestHandler.php 
b/repo/includes/LinkedData/EntityDataRequestHandler.php
index c83cf34..f1f7d40 100644
--- a/repo/includes/LinkedData/EntityDataRequestHandler.php
+++ b/repo/includes/LinkedData/EntityDataRequestHandler.php
@@ -289,11 +289,21 @@
         * @param EntityId $id       The entity
         */
        public function purgeWebCache( EntityId $id ) {
-               $urls = $this->uriManager->getCacheableUrls( $id );
-
                //TODO: use a factory or service, so we can mock & test this
-               $update = new SquidUpdate( $urls );
+               $update = new SquidUpdate( $this->getCacheableUrls( $id ) );
                $update->doUpdate();
+       }
+
+       /**
+        * Produce list of cacheable URLs for this entity.
+        * @param EntityId $id
+        * @return List of Special:EntityData URLs for this entity.
+        */
+       public function getCacheableUrls( $id ) {
+               $params = array(
+                               "flavor" => 
$this->serializationService->getFlavors()
+               );
+               return $this->uriManager->getCacheableUrls( $id, $params );
        }
 
        /**
@@ -517,5 +527,4 @@
 
                // exit normally here, keeping all levels of output buffering.
        }
-
 }
diff --git a/repo/includes/LinkedData/EntityDataSerializationService.php 
b/repo/includes/LinkedData/EntityDataSerializationService.php
index ecd3404..25398b4 100644
--- a/repo/includes/LinkedData/EntityDataSerializationService.php
+++ b/repo/includes/LinkedData/EntityDataSerializationService.php
@@ -368,6 +368,14 @@
        }
 
        /**
+        * Produce list of supported flavors
+        * @return string[]
+        */
+       public function getFlavors() {
+               return array( 'simple', 'dump', 'long', 'full' );
+       }
+
+       /**
         * Creates an Rdf Serializer that can generate the given output format.
         *
         * @param string $format The desired serialization format, as a format 
name understood by ApiBase or RdfWriterFactory
diff --git a/repo/includes/LinkedData/EntityDataUriManager.php 
b/repo/includes/LinkedData/EntityDataUriManager.php
index 587acaa..f279c4a 100644
--- a/repo/includes/LinkedData/EntityDataUriManager.php
+++ b/repo/includes/LinkedData/EntityDataUriManager.php
@@ -195,15 +195,36 @@
         * the given entity.
         *
         * @param EntityId $id
+        * @param array $query Query parameters with values
         *
         * @return string[]
         */
-       public function getCacheableUrls( EntityId $id ) {
+       public function getCacheableUrls( EntityId $id, array $query = array() 
) {
                $urls = array();
 
                foreach ( $this->supportedExtensions as $format => $ext ) {
                        $title = $this->getDocTitle( $id, $format );
                        $urls[] = $title->getInternalURL();
+                       if ( !empty( $query ) ) {
+                               // this can explode really fast so we need to 
be careful
+                               $queries = array ();
+                               foreach ( $query as $name => $values ) {
+                                       $n = rawurlencode( $name );
+                                       $newqueries = array();
+                                       foreach ( $values as $value ) {
+                                               $v = rawurlencode( $value );
+                                               $newqueries[] = array( $n => $v 
);
+                                               foreach ( $queries as $q ) {
+                                                       $q[$n] = $v;
+                                                       $newqueries[] = $q;
+                                               }
+                                       }
+                                       $queries = array_merge($queries, 
$newqueries);
+                               }
+                               foreach ( $queries as $q ) {
+                                       $urls[] = $title->getInternalURL( $q );
+                               }
+                       }
                }
 
                return $urls;
diff --git 
a/repo/tests/phpunit/includes/LinkedData/EntityDataUriManagerTest.php 
b/repo/tests/phpunit/includes/LinkedData/EntityDataUriManagerTest.php
index 53409c3..8f2a937 100644
--- a/repo/tests/phpunit/includes/LinkedData/EntityDataUriManagerTest.php
+++ b/repo/tests/phpunit/includes/LinkedData/EntityDataUriManagerTest.php
@@ -185,9 +185,21 @@
                $base = $title->getInternalURL();
 
                return array(
-                       array( 'Q12', array(
+                       array( 'Q12', array(), array(
                                "$base/Q12.txt",
                                "$base/Q12.rdf",
+                       ) ),
+                       array( 'Q13',
+                               array( "flavor" => array( "vanilla", 
"pistachio", "chocolate" ) ),
+                               array(
+                               "$base/Q13.txt",
+                               "$base/Q13.rdf",
+                       ) ),
+                       array( 'Q14',
+                               array( "flavor" => array( "vanilla", 
"chocolate" ), "toppings" => array( "candy", "fruit" ) ),
+                               array(
+                               "$base/Q14.txt",
+                               "$base/Q14.rdf",
                        ) ),
                );
        }
@@ -195,12 +207,13 @@
        /**
         * @dataProvider provideGetCacheableUrls
         */
-       public function testGetCacheableUrls( $id, $expected ) {
+       public function testGetCacheableUrls( $id, $query, $expected ) {
                $id = $this->idParser->parse( $id );
 
                $uriManager = $this->makeUriManager();
 
-               $actual = $uriManager->getCacheableUrls( $id );
+               $actual = $uriManager->getCacheableUrls( $id, $query );
+               var_export($actual);
                $this->assertEquals( $expected, $actual );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c6d093f5af164e3a4df4493f3aed15d82bb9741
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to