1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +02:00

Update WireCache to avoid loading unnecessary templates plus a minor fix

This commit is contained in:
Ryan Cramer
2022-02-25 11:45:35 -05:00
parent c01c44186e
commit 7d91b43bba

View File

@@ -527,7 +527,7 @@ class WireCache extends Wire {
if($expire instanceof Page) { if($expire instanceof Page) {
// page object // page object
$expire = $expire->template->id; $expire = $expire->templates_id;
} else if($expire instanceof Template) { } else if($expire instanceof Template) {
// template object // template object
@@ -983,6 +983,9 @@ class WireCache extends Wire {
*/ */
public function getInfo($verbose = true, $names = array(), $exclude = array()) { public function getInfo($verbose = true, $names = array(), $exclude = array()) {
$templates = $this->wire()->templates;
$database = $this->wire()->database;
if(is_string($names)) $names = empty($names) ? array() : array($names); if(is_string($names)) $names = empty($names) ? array() : array($names);
if(is_string($exclude)) $exclude = empty($exclude) ? array() : array($exclude); if(is_string($exclude)) $exclude = empty($exclude) ? array() : array($exclude);
@@ -1011,7 +1014,7 @@ class WireCache extends Wire {
$sql .= "WHERE " . implode(' AND ', $wheres); $sql .= "WHERE " . implode(' AND ', $wheres);
} }
$query = $this->wire('database')->prepare($sql); $query = $database->prepare($sql);
foreach($binds as $key => $val) { foreach($binds as $key => $val) {
$query->bindValue($key, $val); $query->bindValue($key, $val);
@@ -1050,20 +1053,20 @@ class WireCache extends Wire {
} }
if(empty($info['expires'])) { if(empty($info['expires'])) {
if($row['expires'] == self::expireNever) { if($row['expires'] === self::expireNever) {
$info['expires'] = $verbose ? 'never' : ''; $info['expires'] = $verbose ? 'never' : '';
} else if($row['expires'] == self::expireReserved) { } else if($row['expires'] === self::expireReserved) {
$info['expires'] = $verbose ? 'reserved' : ''; $info['expires'] = $verbose ? 'reserved' : '';
} else if($row['expires'] == self::expireSave) { } else if($row['expires'] === self::expireSave) {
$info['expires'] = $verbose ? 'when any page or template is modified' : 'save'; $info['expires'] = $verbose ? 'when any page or template is modified' : 'save';
} else if($row['expires'] < time()) { } else if($row['expires'] < self::expireSave) {
$t = strtotime($row['expires']); // potential template ID encoded as date string
foreach($this->wire('templates') as $template) { $templateId = strtotime($row['expires']);
if($template->id == $t) { $template = $templates->get($templateId);
$info['expires'] = $verbose ? "when '$template->name' page or template is modified" : 'save'; if($template) {
$info['template'] = $template->id; $info['expires'] = $verbose ? "when '$template->name' page or template is modified" : 'save';
break; $info['template'] = $template->id;
} break;
} }
} }
if(empty($info['expires'])) { if(empty($info['expires'])) {