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]
This commit is contained in:
Jan Jakes
2023-03-31 12:32:27 +02:00
committed by Aschepikov
parent 54f5addca9
commit ae828b9ac4

View File

@ -17,12 +17,6 @@ class TriggerHandler {
/** @var ActionScheduler */ /** @var ActionScheduler */
private $actionScheduler; private $actionScheduler;
/** @var SubjectLoader */
private $subjectLoader;
/** @var WordPress */
private $wordPress;
/** @var AutomationStorage */ /** @var AutomationStorage */
private $automationStorage; private $automationStorage;
@ -32,25 +26,31 @@ class TriggerHandler {
/** @var Functions */ /** @var Functions */
private $wp; private $wp;
/** @var SubjectLoader */
private $subjectLoader;
/** @var SubjectTransformerHandler */ /** @var SubjectTransformerHandler */
private $subjectTransformerHandler; private $subjectTransformerHandler;
/** @var WordPress */
private $wordPress;
public function __construct( public function __construct(
ActionScheduler $actionScheduler, ActionScheduler $actionScheduler,
SubjectLoader $subjectLoader,
WordPress $wordPress,
AutomationStorage $automationStorage, AutomationStorage $automationStorage,
AutomationRunStorage $automationRunStorage, AutomationRunStorage $automationRunStorage,
Functions $wp, Functions $wp,
SubjectTransformerHandler $subjectTransformerHandler SubjectLoader $subjectLoader,
SubjectTransformerHandler $subjectTransformerHandler,
WordPress $wordPress
) { ) {
$this->actionScheduler = $actionScheduler; $this->actionScheduler = $actionScheduler;
$this->wordPress = $wordPress;
$this->automationStorage = $automationStorage; $this->automationStorage = $automationStorage;
$this->automationRunStorage = $automationRunStorage; $this->automationRunStorage = $automationRunStorage;
$this->subjectLoader = $subjectLoader;
$this->wp = $wp; $this->wp = $wp;
$this->subjectLoader = $subjectLoader;
$this->subjectTransformerHandler = $subjectTransformerHandler; $this->subjectTransformerHandler = $subjectTransformerHandler;
$this->wordPress = $wordPress;
} }
public function initialize(): void { public function initialize(): void {
@ -64,12 +64,9 @@ class TriggerHandler {
return; return;
} }
// ensure subjects are registered and loadable // expand all subject transformations and load subject entries
$subjects = $this->subjectTransformerHandler->getAllSubjects($subjects); $subjects = $this->subjectTransformerHandler->getAllSubjects($subjects);
$subjectEntries = $this->subjectLoader->getSubjectsEntries($subjects); $subjectEntries = $this->subjectLoader->getSubjectsEntries($subjects);
foreach ($subjectEntries as $entry) {
$entry->getPayload();
}
foreach ($automations as $automation) { foreach ($automations as $automation) {
$step = $automation->getTrigger($trigger->getKey()); $step = $automation->getTrigger($trigger->getKey());