From 3dfa9d991bf8c4492274bd254c1ed12cded37d6e Mon Sep 17 00:00:00 2001 From: Igor Wulff Date: Fri, 1 Sep 2023 16:03:57 +0200 Subject: [PATCH] Add orderStatus option hash cache Improve orrderStatusCollection retrieval in cases where this is being called multiple times in a transaction. In combination with the Banner module and getSalesRuleRelatedBanners we've seen behavior where this collection is being called more then 40 times. --- app/code/Magento/Sales/Model/Order/Config.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 92d631d1f78c0..e9d8f7908ff23 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -49,6 +49,11 @@ class Config */ protected $state; + /** + * @var array + */ + private static $orderStatusOptionHashCache; + /** * @var array */ @@ -195,8 +200,10 @@ public function getStateLabel($state) */ public function getStatuses() { - $statuses = $this->orderStatusCollectionFactory->create()->toOptionHash(); - return $statuses; + if (!isset(static::$orderStatusOptionHashCache)) { + static::$orderStatusOptionHashCache = $this->orderStatusCollectionFactory->create()->toOptionHash(); + } + return static::$orderStatusOptionHashCache; } /**