Cenarium has uploaded a new change for review. https://gerrit.wikimedia.org/r/266661
Change subject: TemplateDataBlob: avoid reencoding json ...................................................................... TemplateDataBlob: avoid reencoding json When a TemplateDataBlob is created from json and there is no status error, the json is saved in-class to avoid having to reencode it from the data. Change-Id: I3976e48b9c2cc914960271485e7c8c59ba36aa57 --- M TemplateDataBlob.php 1 file changed, 17 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData refs/changes/61/266661/1 diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php index e1a8371..5a54151 100644 --- a/TemplateDataBlob.php +++ b/TemplateDataBlob.php @@ -21,6 +21,11 @@ private $data; /** + * @var string + */ + private $json; + + /** * @var Status: Cache of TemplateDataBlob::parse */ private $status; @@ -50,6 +55,9 @@ $tdb->data->format = 'inline'; $tdb->data->sets = array(); $tdb->data->maps = new stdClass(); + } else { + // data is unchanged so no need to reencode json + $tdb->json = $json; } $tdb->status = $status; return $tdb; @@ -602,8 +610,8 @@ * @return object */ public function getData() { - // TODO: Returned by reference. Data is a private member. Use clone instead? - return $this->data; + // Return deep clone so callers don't modify data (thus json is unchanged) + return unserialize( serialize( $this->data ) ); } /** @@ -616,7 +624,7 @@ public function getDataInLanguage( $langCode ) { // Deep clone, also need to clone ->params and all interfacetext objects // within param properties. - $data = unserialize( serialize( $this->data ) ); + $data = $this->getData(); // Root.description if ( $data->description !== null ) { @@ -667,7 +675,11 @@ * @return string JSON */ public function getJSON() { - return json_encode( $this->data ); + if ( $this->json === null ) { + // if json is not provided, retrieve it from data + $this->json = json_encode( $this->data ); + } + return $this->json; } /** @@ -859,6 +871,7 @@ private function __construct( $data = null ) { $this->data = $data; + $this->json = null; } } -- To view, visit https://gerrit.wikimedia.org/r/266661 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3976e48b9c2cc914960271485e7c8c59ba36aa57 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/TemplateData Gerrit-Branch: master Gerrit-Owner: Cenarium <cenarium.sy...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits