From ae828b9ac451e19a8b6a5d00ba85ca91d958963f Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Fri, 31 Mar 2023 12:32:27 +0200 Subject: [PATCH] Do not load all possible subjects eagerly With subject transformers the amount of possible subjects will grow, and preloading even those that won't be used may result in performance issues, and unnecessary errors (e.g., caused by 3rd party transformers). [MAILPOET-4946] --- .../Engine/Control/TriggerHandler.php | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php b/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php index da812c81c9..3bec28c8b7 100644 --- a/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php +++ b/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php @@ -17,12 +17,6 @@ class TriggerHandler { /** @var ActionScheduler */ private $actionScheduler; - /** @var SubjectLoader */ - private $subjectLoader; - - /** @var WordPress */ - private $wordPress; - /** @var AutomationStorage */ private $automationStorage; @@ -32,25 +26,31 @@ class TriggerHandler { /** @var Functions */ private $wp; + /** @var SubjectLoader */ + private $subjectLoader; + /** @var SubjectTransformerHandler */ private $subjectTransformerHandler; + /** @var WordPress */ + private $wordPress; + public function __construct( ActionScheduler $actionScheduler, - SubjectLoader $subjectLoader, - WordPress $wordPress, AutomationStorage $automationStorage, AutomationRunStorage $automationRunStorage, Functions $wp, - SubjectTransformerHandler $subjectTransformerHandler + SubjectLoader $subjectLoader, + SubjectTransformerHandler $subjectTransformerHandler, + WordPress $wordPress ) { $this->actionScheduler = $actionScheduler; - $this->wordPress = $wordPress; $this->automationStorage = $automationStorage; $this->automationRunStorage = $automationRunStorage; - $this->subjectLoader = $subjectLoader; $this->wp = $wp; + $this->subjectLoader = $subjectLoader; $this->subjectTransformerHandler = $subjectTransformerHandler; + $this->wordPress = $wordPress; } public function initialize(): void { @@ -64,12 +64,9 @@ class TriggerHandler { return; } - // ensure subjects are registered and loadable + // expand all subject transformations and load subject entries $subjects = $this->subjectTransformerHandler->getAllSubjects($subjects); $subjectEntries = $this->subjectLoader->getSubjectsEntries($subjects); - foreach ($subjectEntries as $entry) { - $entry->getPayload(); - } foreach ($automations as $automation) { $step = $automation->getTrigger($trigger->getKey());