1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-17 20:11:46 +02:00

Update ProcessPageAdd so that it doesn't have to trigger loading of all templates/fieldgroups/fields on every instance and instead only once per session or whenever a change is made in ProcessTemplate

This commit is contained in:
Ryan Cramer
2022-02-11 11:57:51 -05:00
parent 4258870aaa
commit aa4628b638
2 changed files with 19 additions and 14 deletions

View File

@@ -168,20 +168,7 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
$sanitizer = $this->wire()->sanitizer;
$data = $session->getFor($this, 'nav');
if(!empty($data)) {
// check that session cache data is still current
foreach($templates as $template) {
if($template->modified > $data['modified']) {
$data = array();
$session->remove($this, 'nav');
$session->remove($this, 'numAddable');
$this->message("Clearing 'Add New' page cache", Notice::debug);
break;
}
}
}
if(empty($data)) {
$data = array(
@@ -284,6 +271,19 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
return json_encode($data);
}
/**
* Clear "add new" session caches
*
* @since 3.0.194
*
*/
public function clearSessionCaches() {
$session = $this->wire()->session;
$session->removeFor($this, 'nav');
$session->removeFor($this, 'numAddable');
$this->message("Clearing 'Add New' page cache", Notice::debug);
}
/**
* Ask user to select template and parent
*

View File

@@ -3050,6 +3050,11 @@ class ProcessTemplate extends Process implements ConfigurableModule {
sprintf($this->_('Saved template: %s'), $template->name) . ' ' .
($config->debug && count($changes) ? '(' . implode(', ', $changes) . ')' : '')
);
if(count($changes)) {
/** @var ProcessPageAdd $ppa */
$ppa = $modules->get('ProcessPageAdd');
$ppa->clearSessionCaches();
}
} catch(\Exception $e) {
$this->error($e->getMessage());
}