Skip to content

Commit 99ec97b

Browse files
committed
performance improvements in Model::_clearCache
- don't empty cache twice if pluralized name is identical to underscored - refactors for fewer function calls
1 parent 355e2ef commit 99ec97b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/Cake/Model/Model.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,17 +3501,20 @@ public function onError() {
35013501
protected function _clearCache($type = null) {
35023502
if ($type === null) {
35033503
if (Configure::read('Cache.check') === true) {
3504-
$assoc[] = strtolower(Inflector::pluralize($this->alias));
3505-
$assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($this->alias)));
3506-
foreach ($this->_associations as $key => $association) {
3507-
foreach ($this->$association as $key => $className) {
3508-
$check = strtolower(Inflector::pluralize($className['className']));
3509-
if (!in_array($check, $assoc)) {
3510-
$assoc[] = strtolower(Inflector::pluralize($className['className']));
3511-
$assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($className['className'])));
3504+
$pluralized = Inflector::pluralize($this->alias);
3505+
$assoc[$this->alias] = strtolower($pluralized);
3506+
$assoc[] = strtolower(Inflector::underscore($pluralized));
3507+
foreach ($this->_associations as $association) {
3508+
foreach ($this->$association as $associatedClass) {
3509+
$className = $associatedClass['className'];
3510+
if (!isset($assoc[$className])) {
3511+
$pluralized = Inflector::pluralize($className);
3512+
$assoc[$className] = strtolower($pluralized);
3513+
$assoc[] = strtolower(Inflector::underscore($pluralized));
35123514
}
35133515
}
35143516
}
3517+
$assoc = array_unique($assoc);
35153518
clearCache($assoc);
35163519
return true;
35173520
}

0 commit comments

Comments
 (0)