From aa4628b638e4233a37f2e986157a4f07df8c3862 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 11 Feb 2022 11:57:51 -0500 Subject: [PATCH] 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 --- .../ProcessPageAdd/ProcessPageAdd.module | 28 +++++++++---------- .../ProcessTemplate/ProcessTemplate.module | 5 ++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module b/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module index 45be817f..345f66bc 100644 --- a/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module +++ b/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module @@ -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 * diff --git a/wire/modules/Process/ProcessTemplate/ProcessTemplate.module b/wire/modules/Process/ProcessTemplate/ProcessTemplate.module index cc999e6a..ac9d0ec4 100644 --- a/wire/modules/Process/ProcessTemplate/ProcessTemplate.module +++ b/wire/modules/Process/ProcessTemplate/ProcessTemplate.module @@ -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()); }