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

Change subject: Add maint script for forcing a stat cache purge
......................................................................


Add maint script for forcing a stat cache purge

Change-Id: Iec028a09574b687e63286725ead5128061545ac8
---
M includes/stats/ExtDistGraphiteStats.php
A maintenance/purgeCachedStats.php
2 files changed, 56 insertions(+), 1 deletion(-)

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



diff --git a/includes/stats/ExtDistGraphiteStats.php 
b/includes/stats/ExtDistGraphiteStats.php
index f63d1be..e37418a 100644
--- a/includes/stats/ExtDistGraphiteStats.php
+++ b/includes/stats/ExtDistGraphiteStats.php
@@ -39,7 +39,7 @@
                        return false;
                }
 
-               $cacheKey = wfMemcKey( 'extdist', 'ExtDistGraphiteStats', 
$type, 'PopularList' );
+               $cacheKey = $this->getCacheKey( $type );
                $cache = wfGetCache( CACHE_ANYTHING );
 
                $cachedValue = $cache->get( $cacheKey );
@@ -91,4 +91,27 @@
                return $popularList;
        }
 
+       /**
+        * @param string $type
+        *
+        * @return string
+        */
+       private function getCacheKey( $type ) {
+               return wfMemcKey( 'extdist', 'GraphiteStats', $type, 
'PopularList' );
+       }
+
+       public function clearCache() {
+               $cache = wfGetCache( CACHE_ANYTHING );
+               $typesToClear = array(
+                       ExtDistProvider::EXTENSIONS,
+                       ExtDistProvider::SKINS
+               );
+               foreach ( $typesToClear as $type ) {
+                       $success = $cache->delete( $this->getCacheKey( $type ) 
);
+                       if ( !$success ) {
+                               $this->logger->error( "Failed to clear 
PopularList cache for $type" );
+                       }
+               }
+       }
+
 }
diff --git a/maintenance/purgeCachedStats.php b/maintenance/purgeCachedStats.php
new file mode 100644
index 0000000..8f7f287
--- /dev/null
+++ b/maintenance/purgeCachedStats.php
@@ -0,0 +1,32 @@
+<?php
+
+use MediaWiki\Logger\LoggerFactory;
+
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+       $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+       $IP = __DIR__ . '/../../..';
+}
+require_once( "$IP/maintenance/Maintenance.php" );
+
+/**
+ * @author Addshore
+ */
+class ExtDistPurgeCachedStats extends Maintenance {
+
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Purge cached ExtensionDistributor stats";
+       }
+
+       public function execute() {
+               $graphiteStats = new ExtDistGraphiteStats();
+               $graphiteStats->setLogger( LoggerFactory::getInstance( 
'ExtensionDistributor' ) );
+               $graphiteStats->clearCache();
+               $this->output( "Done.\n" );
+       }
+
+}
+
+$maintClass = "ExtDistPurgeCachedStats";
+require_once( RUN_MAINTENANCE_IF_MAIN );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iec028a09574b687e63286725ead5128061545ac8
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/ExtensionDistributor
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
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