Krinkle has uploaded a new change for review.

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


Change subject: TemplateDataBlob: Implement cache versioning
......................................................................

TemplateDataBlob: Implement cache versioning

I ran into countless random exceptoins and errors locally due to
cache I build up over time that was no longer valid. Though in
approved commits in the repository there is only 1 version as of
now, I'm sure we will make changes in the future that require a
cache invalidation since getHtml needs to be able to make
assumptions about what properties exist.

Change-Id: I5f61d6030578a711909435c8b996373e9aaa5178
---
M TemplateData.hooks.php
M TemplateDataBlob.php
M api/ApiTemplateData.php
3 files changed, 21 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData 
refs/changes/16/60316/1

diff --git a/TemplateData.hooks.php b/TemplateData.hooks.php
index d830948..b69a6f9 100644
--- a/TemplateData.hooks.php
+++ b/TemplateData.hooks.php
@@ -86,7 +86,10 @@
                        return '<div class="error">' . $status->getHtml() . 
'</div>';
                }
 
-               $parser->getOutput()->setProperty( 'templatedata', 
$ti->getJSON() );
+               $parser->getOutput()->setProperty( 'templatedata', serialize( 
array(
+                       'version' => TemplateDataBlob::CACHE_VERSION,
+                       'json' => $ti->getJSON(),
+               ) ) );
 
                $parser->getOutput()->addModules( 'ext.templateData' );
 
diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index 25a0b6d..565f711 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -16,6 +16,11 @@
        /**
         * @var stdClass
         */
+       const CACHE_VERSION = 3;
+
+       /**
+        * @var stdClass
+        */
        private $data;
 
        /**
diff --git a/api/ApiTemplateData.php b/api/ApiTemplateData.php
index 808d1ed..0f05e35 100644
--- a/api/ApiTemplateData.php
+++ b/api/ApiTemplateData.php
@@ -79,11 +79,20 @@
                $resp = array();
 
                foreach ( $res as $row ) {
-                       $rawData = $row->pp_value;
+                       $rawValue = $row->pp_value;
+                       $value = unserialize( $rawValue );
+                       if ( !$value ) {
+                               $this->dieUsage( 'Page #' . intval( 
$row->pp_page ) . ' templatedata could not be unserialized', 
'templatedata-corrupt' );
+                       }
+                       $version = $value['version'];
+                       if ( $version !== TemplateDataBlob::CACHE_VERSION ) {
+                               // FIXME: Schedule purge? Regenerate on-demand?
+                               continue;
+                       }
+                       $rawData = $value['json'];
                        $data = json_decode( $rawData );
-
                        if ( !$data ) {
-                               $this->dieUsage( 'Corrupt data found in 
templatedata storage for page #' . intval( $row->pp_page ), 
'templatedata-corrupt' );
+                               $this->dieUsage( 'Page #' . intval( 
$row->pp_page ) . ' templatedata contains invalid JSON as data', 
'templatedata-corrupt' );
                        }
                        $resp[$row->pp_page] = array(
                                'title' => strval( $titles[$row->pp_page] ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5f61d6030578a711909435c8b996373e9aaa5178
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

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

Reply via email to