Browse Source

Optimize view paths caching for plugins.

Closes #2047
ADmad 12 years ago
parent
commit
6bdfdfd436
2 changed files with 16 additions and 3 deletions
  1. 1 0
      lib/Cake/Test/Case/Utility/DebuggerTest.php
  2. 15 3
      lib/Cake/View/View.php

+ 1 - 0
lib/Cake/Test/Case/Utility/DebuggerTest.php

@@ -362,6 +362,7 @@ TEXT;
 	)
 	[protected] _scripts => array()
 	[protected] _paths => array()
+	[protected] _pathsForPlugin => array()
 	[protected] _parents => array()
 	[protected] _current => null
 	[protected] _currentType => ''

+ 15 - 3
lib/Cake/View/View.php

@@ -252,6 +252,13 @@ class View extends Object {
 	protected $_paths = array();
 
 /**
+ * Holds an array of plugin paths.
+ *
+ * @var array
+ */
+	protected $_pathsForPlugin = array();
+
+/**
  * The names of views and their parents used with View::extend();
  *
  * @var array
@@ -1112,8 +1119,13 @@ class View extends Object {
  * @return array paths
  */
 	protected function _paths($plugin = null, $cached = true) {
-		if ($plugin === null && $cached === true && !empty($this->_paths)) {
-			return $this->_paths;
+		if ($cached === true) {
+			if ($plugin === null && !empty($this->_paths)) {
+				return $this->_paths;
+			}
+			if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
+				return $this->_pathsForPlugin[$plugin];
+			}
 		}
 		$paths = array();
 		$viewPaths = App::path('View');
@@ -1145,7 +1157,7 @@ class View extends Object {
 		}
 		$paths = array_merge($paths, $corePaths);
 		if ($plugin !== null) {
-			return $paths;
+			return $this->_pathsForPlugin[$plugin] = $paths;
 		}
 		return $this->_paths = $paths;
 	}