mirror of
https://github.com/processwire/processwire.git
synced 2025-08-18 12:31:17 +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:
@@ -168,20 +168,7 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
|
|||||||
$sanitizer = $this->wire()->sanitizer;
|
$sanitizer = $this->wire()->sanitizer;
|
||||||
|
|
||||||
$data = $session->getFor($this, 'nav');
|
$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)) {
|
if(empty($data)) {
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
@@ -284,6 +271,19 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
|
|||||||
return json_encode($data);
|
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
|
* Ask user to select template and parent
|
||||||
*
|
*
|
||||||
|
@@ -3050,6 +3050,11 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
|||||||
sprintf($this->_('Saved template: %s'), $template->name) . ' ' .
|
sprintf($this->_('Saved template: %s'), $template->name) . ' ' .
|
||||||
($config->debug && count($changes) ? '(' . implode(', ', $changes) . ')' : '')
|
($config->debug && count($changes) ? '(' . implode(', ', $changes) . ')' : '')
|
||||||
);
|
);
|
||||||
|
if(count($changes)) {
|
||||||
|
/** @var ProcessPageAdd $ppa */
|
||||||
|
$ppa = $modules->get('ProcessPageAdd');
|
||||||
|
$ppa->clearSessionCaches();
|
||||||
|
}
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user