Yuvipanda has uploaded a new change for review.

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


Change subject: Add caching & cache invalidation for Campaign pages
......................................................................

Add caching & cache invalidation for Campaign pages

Change-Id: I79fb24997c20118e229585a4c97b45a173f466b1
---
M UploadWizard.php
M includes/CampaignHooks.php
M includes/UploadWizardCampaign.php
3 files changed, 58 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/60/86960/1

diff --git a/UploadWizard.php b/UploadWizard.php
index 9ee1275..320974e 100644
--- a/UploadWizard.php
+++ b/UploadWizard.php
@@ -128,6 +128,7 @@
 $wgHooks[ 'PageContentSaveComplete' ][] = 
'CampaignHooks::onPageContentSaveComplete';
 $wgHooks[ 'ArticleDeleteComplete' ][] = 
'CampaignHooks::onArticleDeleteComplete';
 $wgHooks[ 'TitleMoveComplete' ][] = 'CampaignHooks::onTitleMoveComplete';
+$wgHooks[ 'LinksUpdateComplete' ][] = 'CampaignHooks::onLinksUpdateComplete';
 
 $wgAvailableRights[] = 'upwizcampaigns';
 
diff --git a/includes/CampaignHooks.php b/includes/CampaignHooks.php
index 6c29301..c91ad37 100644
--- a/includes/CampaignHooks.php
+++ b/includes/CampaignHooks.php
@@ -36,11 +36,40 @@
                        $insertData
                );
 
-               $dbw->commit();
+
+        $campaign = new UploadWizardCampaign( $article->getTitle(), 
$content->getJsonData() );
+
+        $templates = $campaign->getTemplates();
+
+        $insertions = array();
+
+        foreach ( $templates as $template ) {
+            $insertions[] = array(
+                'tl_from' => $article->getId(),
+                'tl_namespace' => $template[0],
+                'tl_title' => $template[1]
+            );
+        }
+
+        $success &= $dbw->delete( 'templatelinks',  array( 'tl_from' => 
$article->getId() ) );
+        $success &= $dbw->insert( 'templatelinks', $insertions, __METHOD__, 
array( 'IGNORE' ) );
+
+        $dbw->commit();
 
                return $success;
        }
 
+    public static function onLinksUpdateComplete( LinksUpdate &$linksupdate) {
+               global $wgMemc;
+
+               if( $linksupdate->getTitle()->inNamespace( NS_CAMPAIGN ) ) {
+                       $memKey = wfMemcKey( 'uploadwizard', 'campaign', 
$linksupdate->getTitle()->getDBkey(), 'parsed-config' );
+                       var_dump( "Deleting" + $memKey );
+                       $wgMemc->delete( $memKey );
+               }
+
+        return true;
+    }
        /**
         * Deletes entries from uc_campaigns table when a Campaign is deleted
         */
diff --git a/includes/UploadWizardCampaign.php 
b/includes/UploadWizardCampaign.php
index 3f81bd9..902b95f 100644
--- a/includes/UploadWizardCampaign.php
+++ b/includes/UploadWizardCampaign.php
@@ -35,6 +35,7 @@
         */
        protected $parsedConfig = null;
 
+    protected $templates = array();
 
        /**
         * The Title representing the current campaign
@@ -178,6 +179,14 @@
                return $this->config;
        }
 
+       private function updateTemplates( ParserOutput $parserOutput ) {
+               foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
+                       foreach ( $templates as $dbk => $id ) {
+                               $this->templates[] = array( $ns, $dbk );
+                       }
+               }
+       }
+
        /**
         * Wrapper around OutputPage::parseInline
         *
@@ -204,6 +213,8 @@
                if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
                        $parsed = $m[1];
                }
+
+               $this->updateTemplates( $output );
                wfProfileOut( __METHOD__ );
 
                return $parsed;
@@ -243,8 +254,13 @@
         * @return array
         */
        public function getParsedConfig() {
+               global $wgMemc;
+               $memKey = wfMemcKey( 'uploadwizard', 'campaign', 
$this->getName(), 'parsed-config' );
+
+               $this->parsedConfig = $wgMemc->get( $memKey );
+
                wfProfileIn( __METHOD__ );
-               if ( $this->parsedConfig === null ) {
+               if ( $this->parsedConfig === false ) {
                        $parsedConfig = array();
                        foreach ( $this->config as $key => $value ) {
                                switch ( $key ) {
@@ -270,8 +286,18 @@
                                }
                        }
                        $this->parsedConfig = $parsedConfig;
+                       $wgMemc->set( $memKey, $parsedConfig );
                }
                wfProfileOut( __METHOD__ );
                return $this->parsedConfig;
        }
+
+       public function getTemplates() {
+        if ( $this->parsedConfig === null ) {
+            $this->getParsedConfig();
+        }
+        var_dump( $this->templates );
+        return $this->templates;
+               return array_unique( $this->templates );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I79fb24997c20118e229585a4c97b45a173f466b1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>

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

Reply via email to