Adamw has submitted this change and it was merged.

Change subject: Cache Banner Message Field Definitions
......................................................................


Cache Banner Message Field Definitions

This makes it possible to not have to wikitext parse the banner
content every time we load a banner. This is most useful for
translation when we have to run through each banner to figure
out what needs translating.

This also removes the post save job run configuration variable
because the job should be significantly faster to run now.

Bug: 53769
Bug: 53792
Bug: 53674
Change-Id: I82c8b0ede730dd5e06d796609a63475367e5a571
---
M CentralNotice.php
M includes/Banner.php
M includes/BannerMessageGroup.php
M special/SpecialCentralNoticeBanners.php
4 files changed, 33 insertions(+), 13 deletions(-)

Approvals:
  Adamw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CentralNotice.php b/CentralNotice.php
index 408885c..cd4662d 100644
--- a/CentralNotice.php
+++ b/CentralNotice.php
@@ -121,9 +121,6 @@
 // Whether to use the Translation extension for banner message translation
 $wgNoticeUseTranslateExtension = false;
 
-// True makes translatable banner messages available immediately after save.
-$wgNoticeRunMessageIndexRebuildJobImmediately = true;
-
 // Whether to disable variant languages and use an automatically converted 
version of banners
 // fetched from their parent language (zh for zh-cn, for example) instead.
 $wgNoticeUseLanguageConversion = false;
diff --git a/includes/Banner.php b/includes/Banner.php
index 111bb22..3b25baa 100644
--- a/includes/Banner.php
+++ b/includes/Banner.php
@@ -839,7 +839,7 @@
                                        $pageId = $revision->getPage();
 
                                        // If the banner includes translatable 
messages, tag it for translation
-                                       $fields = $this->extractMessageFields( 
$this->bodyContent );
+                                       $fields = 
$this->getMessageFieldsFromCache( $this->bodyContent );
                                        if ( count( $fields ) > 0 ) {
                                                // Tag the banner for 
translation
                                                Banner::addTag( 
'banner:translate', $revisionId, $pageId, $this->getId() );
@@ -854,6 +854,33 @@
        //<editor-fold desc="Banner message fields">
        function getMessageField( $field_name ) {
                return new BannerMessage( $this->getName(), $field_name );
+       }
+
+       /**
+        * Returns all the message fields in a banner
+        * @see Banner::extractMessageFields()
+        *
+        * @param bool|string $bodyContent If a string will regenerate cache 
object from the string
+        *
+        * @return array|mixed
+        */
+       function getMessageFieldsFromCache( $bodyContent = false ) {
+               global $wgMemc;
+
+               $key = wfMemcKey( 'centralnotice', 'bannerfields', 
$this->getName() );
+               $data = false;
+               if ( $bodyContent === false ) {
+                       $data = $wgMemc->get( $key );
+               }
+
+               if ( $data !== false ) {
+                       $data = json_decode( $data, true );
+               } else {
+                       $data = $this->extractMessageFields( $bodyContent );
+                       $wgMemc->set( $key, json_encode( $data ) );
+               }
+
+               return $data;
        }
 
        /**
@@ -951,7 +978,7 @@
         * @throws Exception
         */
        public function save( $user = null ) {
-               global $wgUser, $wgNoticeRunMessageIndexRebuildJobImmediately;
+               global $wgUser;
 
                $db = CNDatabase::getDb();
 
@@ -984,11 +1011,7 @@
                                // exist in the render job.
                                // TODO: This will go away if we start tracking 
messages in database :)
                                MessageGroups::clearCache();
-                               if ( 
$wgNoticeRunMessageIndexRebuildJobImmediately ) {
-                                       MessageIndexRebuildJob::newJob()->run();
-                               } else {
-                                       return 
JobQueueGroup::singleton()->push( MessageIndexRebuildJob::newJob() );
-                               }
+                               MessageIndexRebuildJob::newJob()->run();
                                $this->runTranslateJob = false;
                        }
 
diff --git a/includes/BannerMessageGroup.php b/includes/BannerMessageGroup.php
index 50e941d..f4dd166 100644
--- a/includes/BannerMessageGroup.php
+++ b/includes/BannerMessageGroup.php
@@ -40,7 +40,7 @@
                $keys = array();
 
                $banner = Banner::fromName( $this->bannerName );
-               $fields = $banner->extractMessageFields();
+               $fields = $banner->getMessageFieldsFromCache();
 
                // The MediaWiki page name convention for messages is the same 
as the
                // convention for banners themselves, except that it doesn't 
include
@@ -66,7 +66,7 @@
                $definitions = array();
 
                $banner = Banner::fromName( $this->bannerName );
-               $fields = $banner->extractMessageFields();
+               $fields = $banner->getMessageFieldsFromCache();
 
                // The MediaWiki page name convention for messages is the same 
as the
                // convention for banners themselves, except that it doesn't 
include
diff --git a/special/SpecialCentralNoticeBanners.php 
b/special/SpecialCentralNoticeBanners.php
index ff7e065..a958495 100644
--- a/special/SpecialCentralNoticeBanners.php
+++ b/special/SpecialCentralNoticeBanners.php
@@ -428,7 +428,7 @@
                }
 
                /* --- Translatable Messages Section --- */
-               $messages = $banner->extractMessageFields( 
$banner->getBodyContent() );
+               $messages = $banner->getMessageFieldsFromCache( 
$banner->getBodyContent() );
 
                if ( $messages ) {
                        // Only show this part of the form if messages exist

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I82c8b0ede730dd5e06d796609a63475367e5a571
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: Adamw <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to