Skip to content

Commit

Permalink
Optimize view paths caching for plugins.
Browse files Browse the repository at this point in the history
Closes #2047
  • Loading branch information
ADmad committed Apr 19, 2014
1 parent d54fbe6 commit 6bdfdfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/Utility/DebuggerTest.php
Expand Up @@ -362,6 +362,7 @@ public function testExportVar() {
)
[protected] _scripts => array()
[protected] _paths => array()
[protected] _pathsForPlugin => array()
[protected] _parents => array()
[protected] _current => null
[protected] _currentType => ''
Expand Down
18 changes: 15 additions & 3 deletions lib/Cake/View/View.php
Expand Up @@ -251,6 +251,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();
*
Expand Down Expand Up @@ -1112,8 +1119,13 @@ protected function _getElementFileName($name) {
* @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');
Expand Down Expand Up @@ -1145,7 +1157,7 @@ protected function _paths($plugin = null, $cached = true) {
}
$paths = array_merge($paths, $corePaths);
if ($plugin !== null) {
return $paths;
return $this->_pathsForPlugin[$plugin] = $paths;
}
return $this->_paths = $paths;
}
Expand Down

0 comments on commit 6bdfdfd

Please sign in to comment.