EBernhardson has uploaded a new change for review.

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

Change subject: Add an onAfterClear data event
......................................................................

Add an onAfterClear data event

Listeners can trigger various data to load and stay loaded.  This new
onAfterClear() event allows listeners to clear that out so when we
clear an ObjectManager we are removing as much old cruft from memory
as possible.

Change-Id: I1eff6195b9d2f2401ecad4bb2529c41ac61761ea
---
M includes/Collection/CollectionCache.php
M includes/Data/Index/FeatureIndex.php
M includes/Data/LifecycleHandler.php
M includes/Data/Listener/AbstractListener.php
M includes/Data/Listener/DeferredInsertLifecycleHandler.php
M includes/Data/Listener/UserNameListener.php
M includes/Data/ObjectManager.php
M includes/Repository/UserNameBatch.php
8 files changed, 35 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/76/204676/1

diff --git a/includes/Collection/CollectionCache.php 
b/includes/Collection/CollectionCache.php
index 58089ef..074c3bb 100644
--- a/includes/Collection/CollectionCache.php
+++ b/includes/Collection/CollectionCache.php
@@ -58,6 +58,10 @@
                return $revision->getCollectionId()->getAlphadecimal() . '-' . 
$revision->getRevisionType() . '-last-rev';
        }
 
+       public function onAfterClear() {
+               $this->lastRevCache = new MapCacheLRU( self::LAST_REV_CACHE_MAX 
);
+       }
+
        public function onAfterInsert( $object, array $new, array $metadata ) {
                if ( $object instanceof AbstractRevision ) {
                        $this->lastRevCache->clear( $this->getLastRevCacheKey( 
$object ) );
diff --git a/includes/Data/Index/FeatureIndex.php 
b/includes/Data/Index/FeatureIndex.php
index 8d56cfd..61dc07d 100644
--- a/includes/Data/Index/FeatureIndex.php
+++ b/includes/Data/Index/FeatureIndex.php
@@ -360,6 +360,13 @@
        /**
         * {@inheritDoc}
         */
+       public function onAfterClear() {
+               // nothing to do
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public function find( array $attributes, array $options = array() ) {
                $results = $this->findMulti( array( $attributes ), $options );
                return reset( $results );
diff --git a/includes/Data/LifecycleHandler.php 
b/includes/Data/LifecycleHandler.php
index b1ee3a8..2c0612d 100644
--- a/includes/Data/LifecycleHandler.php
+++ b/includes/Data/LifecycleHandler.php
@@ -11,4 +11,5 @@
        function onAfterInsert( $object, array $new, array $metadata );
        function onAfterUpdate( $object, array $old, array $new, array 
$metadata );
        function onAfterRemove( $object, array $old, array $metadata );
+       function onAfterClear();
 }
diff --git a/includes/Data/Listener/AbstractListener.php 
b/includes/Data/Listener/AbstractListener.php
index 62637b0..079f70a 100644
--- a/includes/Data/Listener/AbstractListener.php
+++ b/includes/Data/Listener/AbstractListener.php
@@ -40,4 +40,10 @@
         */
        public function onAfterInsert( $revision, array $row, array $metadata ) 
{
        }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function onAfterClear() {
+       }
 }
diff --git a/includes/Data/Listener/DeferredInsertLifecycleHandler.php 
b/includes/Data/Listener/DeferredInsertLifecycleHandler.php
index 23332fb..02c16f3 100644
--- a/includes/Data/Listener/DeferredInsertLifecycleHandler.php
+++ b/includes/Data/Listener/DeferredInsertLifecycleHandler.php
@@ -63,4 +63,9 @@
        public function onAfterLoad( $object, array $old ) {
                $this->nested->onAfterLoad( $object, $old );
        }
+
+       public function onAfterClear() {
+               // Not clearing $this->queue, this is not data but actual code
+               // that needs to be run.
+       }
 }
diff --git a/includes/Data/Listener/UserNameListener.php 
b/includes/Data/Listener/UserNameListener.php
index abb70c9..7655c1e 100644
--- a/includes/Data/Listener/UserNameListener.php
+++ b/includes/Data/Listener/UserNameListener.php
@@ -33,6 +33,10 @@
                }
        }
 
+       public function onAfterClear() {
+               $this->batch->clear();
+       }
+
        /**
         * Load any user ids in $row into the username batch
         */
diff --git a/includes/Data/ObjectManager.php b/includes/Data/ObjectManager.php
index 7e604d5..ab1a36b 100644
--- a/includes/Data/ObjectManager.php
+++ b/includes/Data/ObjectManager.php
@@ -100,6 +100,9 @@
        public function clear() {
                $this->loaded = new SplObjectStorage;
                $this->mapper->clear();
+               foreach ( $this->lifecycleHandlers as $handler ) {
+                       $handler->onAfterClear();
+               }
        }
 
        /**
diff --git a/includes/Repository/UserNameBatch.php 
b/includes/Repository/UserNameBatch.php
index 72a0448..e3a86ee 100644
--- a/includes/Repository/UserNameBatch.php
+++ b/includes/Repository/UserNameBatch.php
@@ -38,6 +38,11 @@
                }
        }
 
+       public function clear() {
+               $this->queued = array();
+               $this->usernames = array();
+       }
+
        /**
         * @param string $wiki
         * @param integer $userId

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1eff6195b9d2f2401ecad4bb2529c41ac61761ea
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to