Skip to content

Commit

Permalink
performance improvements in Model::_clearCache
Browse files Browse the repository at this point in the history
- don't empty cache twice if pluralized name is identical to underscored
- refactors for fewer function calls
  • Loading branch information
Schlaefer committed Sep 27, 2013
1 parent 355e2ef commit 99ec97b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/Cake/Model/Model.php
Expand Up @@ -3501,17 +3501,20 @@ public function onError() {
protected function _clearCache($type = null) {
if ($type === null) {
if (Configure::read('Cache.check') === true) {
$assoc[] = strtolower(Inflector::pluralize($this->alias));
$assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($this->alias)));
foreach ($this->_associations as $key => $association) {
foreach ($this->$association as $key => $className) {
$check = strtolower(Inflector::pluralize($className['className']));
if (!in_array($check, $assoc)) {
$assoc[] = strtolower(Inflector::pluralize($className['className']));
$assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($className['className'])));
$pluralized = Inflector::pluralize($this->alias);
$assoc[$this->alias] = strtolower($pluralized);
$assoc[] = strtolower(Inflector::underscore($pluralized));
foreach ($this->_associations as $association) {
foreach ($this->$association as $associatedClass) {
$className = $associatedClass['className'];
if (!isset($assoc[$className])) {
$pluralized = Inflector::pluralize($className);
$assoc[$className] = strtolower($pluralized);
$assoc[] = strtolower(Inflector::underscore($pluralized));
}
}
}
$assoc = array_unique($assoc);
clearCache($assoc);
return true;
}
Expand Down

0 comments on commit 99ec97b

Please sign in to comment.