From 53ba5f215c7795c73080b5d8e678d753d685d13d Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 26 Dec 2013 15:34:05 +0100 Subject: [PATCH] Reduce memory usage --- lib/Alchemy/Phrasea/Authentication/ACLProvider.php | 2 +- lib/classes/User/Adapter.php | 11 +++++------ lib/classes/appbox.php | 6 ------ lib/classes/caption/Field/Value.php | 5 +++++ lib/classes/caption/field.php | 5 +++++ lib/classes/collection.php | 5 +++++ lib/classes/connection.php | 2 +- lib/classes/databox.php | 5 +++++ lib/classes/databox/field.php | 5 +++++ lib/classes/databox/status.php | 5 +++++ lib/classes/patch/320alpha4b.php | 5 +++++ lib/classes/thesaurus/xpath.php | 5 +++++ tests/classes/PhraseanetTestCase.php | 11 +++++++++++ 13 files changed, 58 insertions(+), 14 deletions(-) diff --git a/lib/Alchemy/Phrasea/Authentication/ACLProvider.php b/lib/Alchemy/Phrasea/Authentication/ACLProvider.php index 61d1bd1a4d..ac9f9ceda1 100644 --- a/lib/Alchemy/Phrasea/Authentication/ACLProvider.php +++ b/lib/Alchemy/Phrasea/Authentication/ACLProvider.php @@ -49,7 +49,7 @@ class ACLProvider /** * Purges ACL cache */ - public function purge() + public static function purge() { self::$cache = []; } diff --git a/lib/classes/User/Adapter.php b/lib/classes/User/Adapter.php index 06fcfb0862..e4f476d4af 100644 --- a/lib/classes/User/Adapter.php +++ b/lib/classes/User/Adapter.php @@ -47,12 +47,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface */ protected $_prefs = []; - /** - * - * @var array - */ - protected static $_users = []; - /** * * @var array @@ -1352,4 +1346,9 @@ class User_Adapter implements User_Interface, cache_cacheableInterface return $vars; } + + public static function purge() + { + self::$_instance = []; + } } diff --git a/lib/classes/appbox.php b/lib/classes/appbox.php index a8ad4ab329..fb5a9aa0c6 100644 --- a/lib/classes/appbox.php +++ b/lib/classes/appbox.php @@ -27,12 +27,6 @@ class appbox extends base */ protected $id; - /** - * - * @var appbox - */ - protected static $_instance; - /** * * constant defining the app type diff --git a/lib/classes/caption/Field/Value.php b/lib/classes/caption/Field/Value.php index e2fd7c486b..fcd2950539 100644 --- a/lib/classes/caption/Field/Value.php +++ b/lib/classes/caption/Field/Value.php @@ -465,4 +465,9 @@ class caption_Field_Value implements cache_cacheableInterface unset(self::$localCache[$this->get_cache_key($option)]); } + + public static function purge() + { + self::$localCache = []; + } } diff --git a/lib/classes/caption/field.php b/lib/classes/caption/field.php index a4ea5530d6..6b32f73ad6 100644 --- a/lib/classes/caption/field.php +++ b/lib/classes/caption/field.php @@ -448,4 +448,9 @@ class caption_field implements cache_cacheableInterface { unset(self::$localCache[$this->get_cache_key($option)]); } + + public static function purge() + { + self::$localCache = []; + } } diff --git a/lib/classes/collection.php b/lib/classes/collection.php index d72b411073..af0602c115 100644 --- a/lib/classes/collection.php +++ b/lib/classes/collection.php @@ -730,4 +730,9 @@ class collection implements cache_cacheableInterface { return $this->databox->delete_data_from_cache($this->get_cache_key($option)); } + + public static function purge() + { + self::$_collections = []; + } } diff --git a/lib/classes/connection.php b/lib/classes/connection.php index a7a306bc7f..e9ed6f516e 100644 --- a/lib/classes/connection.php +++ b/lib/classes/connection.php @@ -53,7 +53,7 @@ class connection */ public static function printLog(Application $app) { - if (!$app['debug']) { + if ($app->getEnvironment() !== Application::ENV_DEV) { return; } diff --git a/lib/classes/databox.php b/lib/classes/databox.php index 5c41479b00..1bcf43ad26 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -1464,4 +1464,9 @@ class databox extends base } parent::delete_data_from_cache($option); } + + public static function purge() + { + self::$_xpath_thesaurus = self::$_dom_thesaurus = self::$_thesaurus = self::$_sxml_thesaurus = []; + } } diff --git a/lib/classes/databox/field.php b/lib/classes/databox/field.php index a70601b5d8..145d45ed9c 100644 --- a/lib/classes/databox/field.php +++ b/lib/classes/databox/field.php @@ -1071,4 +1071,9 @@ class databox_field implements cache_cacheableInterface } } + + public static function purge() + { + self::$_instance = []; + } } diff --git a/lib/classes/databox/status.php b/lib/classes/databox/status.php index 19f74b6fe4..877d6fc1b1 100644 --- a/lib/classes/databox/status.php +++ b/lib/classes/databox/status.php @@ -587,4 +587,9 @@ class databox_status return $status; } + + public static function purge() + { + self::$_status = self::$_statuses = []; + } } diff --git a/lib/classes/patch/320alpha4b.php b/lib/classes/patch/320alpha4b.php index f5398272bc..671a603e19 100644 --- a/lib/classes/patch/320alpha4b.php +++ b/lib/classes/patch/320alpha4b.php @@ -236,4 +236,9 @@ class patch_320alpha4b implements patchInterface return $feed; } + + public static function purge() + { + self::$feeds = []; + } } diff --git a/lib/classes/thesaurus/xpath.php b/lib/classes/thesaurus/xpath.php index fe3a49c33c..01e3f6184f 100644 --- a/lib/classes/thesaurus/xpath.php +++ b/lib/classes/thesaurus/xpath.php @@ -35,4 +35,9 @@ class thesaurus_xpath extends DOMXPath return(self::$r[$context_path]); } + + public static function purge() + { + self::$r = []; + } } diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index 45b03aa880..dd51917139 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -220,6 +220,7 @@ abstract class PhraseanetTestCase extends WebTestCase public static function tearDownAfterClass() { self::$testCaseBooted = false; + gc_collect_cycles(); parent::tearDownAfterClass(); } @@ -298,6 +299,16 @@ abstract class PhraseanetTestCase extends WebTestCase public function tearDown() { + \Alchemy\Phrasea\Authentication\ACLProvider::purge(); + \collection::purge(); + \databox::purge(); + \caption_field::purge(); + \caption_Field_Value::purge(); + \databox_field::purge(); + \databox_status::purge(); + \thesaurus_xpath::purge(); + \User_Adapter::purge(); + /** * Kris Wallsmith pro-tip * @see http://kriswallsmith.net/post/18029585104/faster-phpunit