Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53897
Change subject: cache cleanup script
......................................................................
cache cleanup script
Change-Id: I6a1ff5f0f62cbb44563528f432b2924150bc169c
---
M ArticleFeedbackv5.backend.LBFactory.php
M data/maintenance/DataModelPurgeCache.php
A maintenance/purgeCache.php
3 files changed, 138 insertions(+), 25 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleFeedbackv5
refs/changes/97/53897/1
diff --git a/ArticleFeedbackv5.backend.LBFactory.php
b/ArticleFeedbackv5.backend.LBFactory.php
index 61f73e9..8333cd7 100644
--- a/ArticleFeedbackv5.backend.LBFactory.php
+++ b/ArticleFeedbackv5.backend.LBFactory.php
@@ -44,9 +44,8 @@
$ids = null;
if ( $id != null ) {
$ids = (array) $id;
+ $ids = array_map( array( $this, 'standardizeId' ), $ids
);
}
-
- $ids = array_map( array( $this, 'standardizeId' ), $ids );
return parent::get( $ids, $shard );
}
diff --git a/data/maintenance/DataModelPurgeCache.php
b/data/maintenance/DataModelPurgeCache.php
index d1414e7..a549bdd 100644
--- a/data/maintenance/DataModelPurgeCache.php
+++ b/data/maintenance/DataModelPurgeCache.php
@@ -2,7 +2,7 @@
require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
- : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
+ : dirname( __FILE__ ) . '/../../../../maintenance/Maintenance.php' );
/**
* This will purge all DataModel caches.
@@ -15,7 +15,14 @@
*
* @var int
*/
- private $completeCount = 0;
+ protected $completeCount = 0;
+
+ /**
+ * Array of shard ids
+ *
+ * @var array
+ */
+ protected $shards = array( null );
/**
* Constructor
@@ -38,7 +45,6 @@
*/
public function execute() {
$class = $this->getClass();
- $shards = array( null );
$this->output( "Purging $class caches.\n" );
@@ -46,40 +52,65 @@
$rows = $class::getBackend()->get( null, null );
foreach ( $rows as $i => $row ) {
- if ( !in_array( $row->{$class::getShardColumn()},
$shards ) ) {
- $shards[] = $row->{$class::getShardColumn()};
+ if ( !in_array( $row->{$class::getShardColumn()},
$this->shards ) ) {
+ $this->shards[] =
$row->{$class::getShardColumn()};
}
- // clear cached entries
- $entry = $class::loadFromRow( $row );
- $entry->uncache();
+ $object = $class::loadFromRow( $row );
+
+ $this->purgeObject( $object );
$this->completeCount++;
- wfWaitForSlaves();
-
if ( $i % 50 == 0 ) {
- $this->output( "--purged caches to entry
#".$entry->{$class::getIdColumn()}."\n" );
+ $this->output( "--purged caches to entry
#".$object->{$class::getIdColumn()}."\n" );
+ wfWaitForSlaves();
}
}
- foreach ( $class::$lists as $list => $properties ) {
- foreach ( $shards as $shard ) {
- // clear lists
- $key = wfMemcKey( get_called_class(),
'getListValidity', $list, $shard );
- $class::getCache()->delete( $key );
+ foreach ( $this->shards as $i => $shard ) {
+ $this->purgeShard( $shard );
- // clear counts
- $key = wfMemcKey( $class, 'getCount', $list,
$shard );
- $class::getCache()->delete( $key );
+ if ( $i % 50 == 0 ) {
+ $this->output( "--purged caches to shard
#$shard\n" );
+ wfWaitForSlaves();
}
-
- $this->output( "--purged caches for list #".$list."\n"
);
}
$this->output( "Done. Purged caches for $this->completeCount
$class entries.\n" );
}
+
+ /**
+ * Per-object cache removal
+ *
+ * @param DataModel $object The object
+ */
+ public function purgeObject( DataModel $object ) {
+ $object->uncache();
+ }
+
+ /**
+ * Per-shard cache removal
+ *
+ * @param mixed $shard The shard column's value
+ */
+ public function purgeShard( $shard ) {
+ $class = $this->getClass();
+
+ foreach ( $class::$lists as $list => $properties ) {
+ // clear lists
+ $key = wfMemcKey( get_called_class(),
'getListValidity', $list, $shard );
+ $class::getCache()->delete( $key );
+
+ // clear counts
+ $key = wfMemcKey( $class, 'getCount', $list, $shard );
+ $class::getCache()->delete( $key );
+ }
+ }
}
-$maintClass = "DataModelPurgeCache";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+// allow extension-specific override before including this file
+if ( !isset( $maintClassOverride ) || !$maintClassOverride ) {
+ $maintClass = "DataModelPurgeCache";
+ require_once( RUN_MAINTENANCE_IF_MAIN );
+}
diff --git a/maintenance/purgeCache.php b/maintenance/purgeCache.php
new file mode 100644
index 0000000..ec554d8
--- /dev/null
+++ b/maintenance/purgeCache.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * DataModelPurgeClass is a good starting point to purge all caches;
+ * extend that class and add some more caches to be clear here.
+ */
+$maintClassOverride = true;
+require_once __DIR__ . '/../data/maintenance/DataModelPurgeCache.php';
+
+/**
+ * This will purge all ArticleFeedbackv5 caches.
+ *
+ * @ingroup Maintenance
+ */
+class ArticleFeedbackv5_PurgeCache extends DataModelPurgeCache {
+ /**
+ * Constructor
+ */
+ public function __construct() {
+ parent::__construct();
+
+ $this->deleteOption( 'model' );
+ $this->mDescription = 'Purge all ArticleFeedbackv5 caches.';
+ }
+
+ /**
+ * @return string
+ */
+ public function getClass() {
+ return 'ArticleFeedbackv5Model';
+ }
+
+ /**
+ * Execute the script
+ */
+ public function execute() {
+ parent::execute();
+
+ // clear max user id
+ global $wgMemc;
+ $wgMemc->delete( wfMemcKey( 'articlefeedbackv5', 'maxUserId' )
);
+ }
+
+ /**
+ * Per-object cache removal
+ *
+ * @param ArticleFeedbackv5Model $object The object
+ */
+ public function purgeObject( DataModel $object ) {
+ parent::purgeObject( $object );
+
+ global $wgMemc;
+
+ // feedback activity count per permission
+ global $wgArticleFeedbackv5Permissions;
+ foreach( $wgArticleFeedbackv5Permissions as $permission ) {
+ $key = wfMemcKey( 'articlefeedbackv5',
'getActivityCount', $permission, $object->aft_id );
+ $wgMemc->delete( $key );
+ }
+
+ // feedback last editor activity
+ $key = wfMemcKey( get_called_class(), 'getLastEditorActivity',
$object->aft_id );
+ $wgMemc->delete( $key );
+ }
+
+ /**
+ * Per-shard cache removal
+ *
+ * @param mixed $shard The shard column's value
+ */
+ public function purgeShard( $shard ) {
+ parent::purgeShard( $shard );
+
+ $class = $this->getClass();
+
+ // clear page found percentage
+ $key = wfMemcKey( get_called_class(), 'getCountFound', $shard );
+ $class::getCache()->delete( $key );
+ }
+}
+
+$maintClass = 'ArticleFeedbackv5_PurgeCache';
+require_once( RUN_MAINTENANCE_IF_MAIN );
--
To view, visit https://gerrit.wikimedia.org/r/53897
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6a1ff5f0f62cbb44563528f432b2924150bc169c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits