jenkins-bot has submitted this change and it was merged.
Change subject: Cache the JSON blocks using memcached
......................................................................
Cache the JSON blocks using memcached
JSON blocks are now saved to the cache when the JSON block is edited
or when the JSON block is loaded and doesn't already exist in the
cache.
Change-Id: Ia7c34bf295aab4ef4965a7331f5369a19492b69c
---
M BookManagerv2.hooks.php
M includes/JsonHooks.php
2 files changed, 22 insertions(+), 3 deletions(-)
Approvals:
Mwalker: Looks good to me, approved
jenkins-bot: Verified
diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index 69a32be..245a0a4 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -309,7 +309,7 @@
global $wgContentNamespaces;
if ( in_array( $out->getTitle()->getNamespace(),
$wgContentNamespaces ) ) {
if ( $out->getRevisionId() !== null ) {
- global $wgContLang,
$wgBookManagerv2ExampleNavigation;
+ global $wgContLang,
$wgBookManagerv2ExampleNavigation, $wgMemc;
$categories = $out->getCategories();
$namespace = $wgContLang->convertNamespace(
NS_BOOK ) . ":";
$out->addModuleStyles( "ext.BookManagerv2" );
@@ -320,7 +320,14 @@
if ( substr( $cat, 0, strlen(
$namespace ) ) === $namespace ) {
$jsonPageTitle =
Title::newFromText( $cat );
if ( $jsonPageTitle->exists() )
{
- $jsonBook =
self::getJson( $jsonPageTitle );
+ // Check for cached
version of the JSON block, otherwise
+ // get it from the DB
and set the value in the cache.
+ $cacheKey = wfMemcKey(
'BookManagerv2', $jsonPageTitle->getArticleID(), 'json' );
+ $jsonBook =
$wgMemc->get( $cacheKey );
+ if ( $jsonBook ===
false ) {
+ $jsonBook =
self::getJson( $jsonPageTitle );
+ $wgMemc->set(
$cacheKey, $jsonBook );
+ }
break;
}
}
diff --git a/includes/JsonHooks.php b/includes/JsonHooks.php
index 3322f88..bd9fdd8 100644
--- a/includes/JsonHooks.php
+++ b/includes/JsonHooks.php
@@ -69,17 +69,29 @@
* @return True
*/
static function onEditFilterMerged( $editor, $text, &$error, $summary )
{
- if ( $editor->getTitle()->getNamespace() !== NS_BOOK ) {
+ $pageTitle = $editor->getTitle();
+ if ( $pageTitle->getNamespace() !== NS_BOOK ) {
return true;
}
+ global $wgMemc;
$content = new JsonBookContent( $text );
try {
$content->validate();
+ $blockIsValid = true;
} catch ( JsonSchemaException $e ) {
$error = $e->getMessage();
+ $blockIsValid = false;
}
+
+ if ( $blockIsValid ) {
+ //Add to cache
+ $cacheKey = wfMemcKey( 'BookManagerv2',
$pageTitle->getArticleID(), 'json' );
+ $wgMemc->set( wfMemcKey( $cacheKey ),
+ FormatJson::decode( $content->getNativeData(),
false ));
+ }
+
return true;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/74803
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia7c34bf295aab4ef4965a7331f5369a19492b69c
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/BookManagerv2
Gerrit-Branch: master
Gerrit-Owner: Mollywhite <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Mollywhite <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits