From e885c7e7b6d29e503e7d3d997b2168756c036f41 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Tue, 27 Nov 2012 11:39:42 +0000
Subject: [PATCH] Optimisation performances

---
 library/Class/Article.php | 14 ++++++++++++--
 library/Class/Profil.php  | 31 ++++++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/library/Class/Article.php b/library/Class/Article.php
index 59a2de89144..a043821f3e8 100644
--- a/library/Class/Article.php
+++ b/library/Class/Article.php
@@ -595,12 +595,22 @@ class Class_Article extends Storm_Model_Abstract {
 			->setContenu($original->getContenu());
 	}
 
+
+
+	/**
+   * Surcharge la methode storm pour raisons de performances
+	 * @return bool
+	 */
+	public function hasArticleOriginal() {
+		return null !== $this->_get('article_original');
+  }
+
+
 	/**
 	 * @return bool
 	 */
 	public function isTraduction() {
-		$is_trad = $this->hasArticleOriginal();
-		return $is_trad;
+		return $this->hasArticleOriginal();
 	}
 
 	/**
diff --git a/library/Class/Profil.php b/library/Class/Profil.php
index 67d7a7cdb0f..ea4e68eab74 100644
--- a/library/Class/Profil.php
+++ b/library/Class/Profil.php
@@ -74,6 +74,11 @@ class Class_Profil extends Storm_Model_Abstract {
   protected static $_current_profil;
   protected static $DEFAULT_VALUES, $CFG_SITE_KEYS, $FORWARDED_ATTRIBUTES;
 
+	// cache des attributs pour raison de performances
+	protected $_has_parent_profil;
+	protected $_cfg_site_array;
+	protected $_should_forward_attributes = [];
+
 	/**
 	 * liste des bannieres
 	 * @var array
@@ -262,11 +267,23 @@ class Class_Profil extends Storm_Model_Abstract {
 	 * @return bool
 	 */
 	public function shouldForwardAttributeToParent($field) {
-		return
-			in_array($field, self::getAttributesForwardedToParent())
-			and $this->hasParentProfil();
+		if (!isset($this->_should_forward_attributes[$field]))
+			$this->_should_forward_attributes[$field] = in_array($field, self::getAttributesForwardedToParent()) && $this->hasParentProfil();
+		return $this->_should_forward_attributes[$field];
 	}
 
+
+	/**
+	 * Surcharge la methode storm pour raisons de performances
+	 * @return bool
+	 */
+	public function hasParentProfil() {
+		if (!isset($this->_has_parent_profil))
+			$this->_has_parent_profil = (null != $this->_get('parent_profil'));
+		return $this->_has_parent_profil;
+	}
+
+
 	/**
 	 * @param Class_I18nTranslator $translator
 	 * @return Class_Profil
@@ -558,7 +575,9 @@ class Class_Profil extends Storm_Model_Abstract {
 	 * @return array
 	 */
 	public function getCfgSiteAsArray() {
-		return $this->_getCfgAsArrayNamed('Site');
+		if (!isset($this->_cfg_site_array))
+			$this->_cfg_site_array = $this->_getCfgAsArrayNamed('Site');
+		return $this->_cfg_site_array;
 	}
 
 
@@ -674,7 +693,9 @@ class Class_Profil extends Storm_Model_Abstract {
 	 * @return Class_Profil
 	 */
 	public function setCfgSite($string_or_array) {
-		return $this->_setCfgNamed('cfg_site', $string_or_array);
+		$this->_setCfgNamed('cfg_site', $string_or_array);
+		$this->_cfg_site_array = null;
+		return $this;
 	}
 
 
-- 
GitLab