jenkins-bot has submitted this change and it was merged.

Change subject: Conversion to using WAN cache
......................................................................


Conversion to using WAN cache

Bug: T93141
Change-Id: I27392d59dae39953b1054e51620b329c6491721a
---
M includes/ArticleMetadata.php
M includes/PageTriage.php
M includes/PageTriageUtil.php
3 files changed, 11 insertions(+), 56 deletions(-)

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



diff --git a/includes/ArticleMetadata.php b/includes/ArticleMetadata.php
old mode 100644
new mode 100755
index c6854e5..abb388f
--- a/includes/ArticleMetadata.php
+++ b/includes/ArticleMetadata.php
@@ -42,54 +42,20 @@
        }
 
        /**
-        * Update the metadata in cache
-        * @param $update array - key => value pair for update
-        * @param $pageId int
-        */
-       public function updateMetadataInCache( $update, $pageId = null ) {
-               global $wgMemc;
-
-               $keyPrefix = $this->memcKeyPrefix();
-
-               if ( $pageId ) {
-                       $pageId = array( $pageId );
-               } else {
-                       $pageId = $this->mPageId;
-               }
-
-               foreach ( $pageId as $val ) {
-                       $wgMemc->merge(
-                               $keyPrefix . '-' . $val,
-                               function( BagOStuff $cache, $key, $data ) use( 
$update ) {
-                                       // data exists in cache, update the data
-                                       if ( $data !== false ) {
-                                               return array_merge( $data, 
$update );
-                                       // data doesn't exist in cache, don't 
do anything
-                                       // with the partial update
-                                       } else {
-                                               return false;
-                                       }
-                               },
-                               86400
-                       );
-               }
-       }
-
-       /**
         * Flush the metadata in cache
         * @param $pageId - page id to be flushed, if null is provided, all
         *                  page id in $this->mPageId will be flushed
         */
        public function flushMetadataFromCache( $pageId = null ) {
-               global $wgMemc;
+               $cache = ObjectCache::getMainWANInstance();
 
                $keyPrefix = $this->memcKeyPrefix();
                if ( is_null( $pageId ) ) {
                        foreach ( $this->mPageId as $pageId ) {
-                               $wgMemc->delete(  $keyPrefix . '-' . $pageId );
+                               $cache->delete(  $keyPrefix . '-' . $pageId );
                        }
                } else {
-                       $wgMemc->delete(  $keyPrefix . '-' . $pageId );
+                       $cache->delete(  $keyPrefix . '-' . $pageId );
                }
        }
 
@@ -99,10 +65,9 @@
         * @param $singleData mixed - data to be saved
         */
        public function setMetadataToCache( $pageId, $singleData ) {
-               global $wgMemc;
-
+               $cache = ObjectCache::getMainWANInstance();
                $this->flushMetadataFromCache( $pageId );
-               $wgMemc->set(  $this->memcKeyPrefix() . '-' . $pageId, 
$singleData, 86400 ); // 24 hours
+               $cache->set(  $this->memcKeyPrefix() . '-' . $pageId, 
$singleData, 86400 ); // 24 hours
        }
 
        /**
@@ -112,21 +77,21 @@
         * @return array
         */
        public function getMetadataFromCache( $pageId = null ) {
-               global $wgMemc;
+               $cache = ObjectCache::getMainWANInstance();
 
                $keyPrefix = $this->memcKeyPrefix();
 
                if ( is_null( $pageId ) ) {
                        $metaData = array();
                        foreach ( $this->mPageId as $pageId ) {
-                               $metaDataCache = $wgMemc->get( $keyPrefix . '-' 
. $pageId );
+                               $metaDataCache = $cache->get( $keyPrefix . '-' 
. $pageId );
                                if ( $metaDataCache !== false ) {
                                        $metaData[$pageId] = $metaDataCache;
                                }
                        }
                        return $metaData;
                } else {
-                       return $wgMemc->get( $keyPrefix . '-' . $pageId );
+                       return $cache->get( $keyPrefix . '-' . $pageId );
                }
        }
 
@@ -243,8 +208,8 @@
         */
        public static function getValidTags() {
                global $wgPageTriageCacheVersion, $wgMemc;
-               $key = wfMemcKey( 'pagetriage', 'valid', 'tags', 
$wgPageTriageCacheVersion );
 
+               $key = wfMemcKey( 'pagetriage', 'valid', 'tags', 
$wgPageTriageCacheVersion );
                $tags = $wgMemc->get( $key );
                if ( $tags === false  ) {
                        $tags = array();
diff --git a/includes/PageTriage.php b/includes/PageTriage.php
old mode 100644
new mode 100755
index 9fd8042..0d017c0
--- a/includes/PageTriage.php
+++ b/includes/PageTriage.php
@@ -131,21 +131,11 @@
                }
                $dbw->commit();
 
-               // update the cache
-               $changedCacheFields = array(
-                       'reviewer' => $user ? $user->getName() : '',
-                       'patrol_status' => $this->mReviewed,
-                       'ptrp_reviewed_updated' => wfTimestamp( TS_MW, 
$this->mReviewedUpdated ),
-                       'ptrp_last_reviewed_by' => $this->mLastReviewedBy
-               );
-
                $articleMetadata = new ArticleMetadata( array( $this->mPageId ) 
);
                $metadataArray = $articleMetadata->getMetadata();
 
                if( array_key_exists( $this->mPageId, $metadataArray ) ) {
-                       // array_merge will overwrite the previous array
-                       $newMetadata = array_merge( 
$metadataArray[$this->mPageId], $changedCacheFields );
-                       $articleMetadata->setMetadataToCache( $this->mPageId, 
$newMetadata );
+                       $articleMetadata->flushMetadataFromCache( 
$this->mPageId );
                }
        }
 
diff --git a/includes/PageTriageUtil.php b/includes/PageTriageUtil.php
old mode 100644
new mode 100755
index 7b3d312..17718dd
--- a/includes/PageTriageUtil.php
+++ b/includes/PageTriageUtil.php
@@ -387,7 +387,7 @@
                $dbw->commit();
 
                $metadata = new ArticleMetadata( $pageIds );
-               $metadata->updateMetadataInCache( array( 'user_block_status' => 
$status ) );
+               $metadata->flushMetadataFromCache();
        }
 
        private static function getCacheVersion() {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I27392d59dae39953b1054e51620b329c6491721a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageTriage
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to