File tree Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ class ProductRenderListPlugin
4949 */
5050 private $ logger ;
5151
52+ /**
53+ * @var array Cache for customer group IDs
54+ */
55+ private $ customerGroupCache = [];
56+
5257 /**
5358 * @param UserContextInterface $userContext
5459 * @param CustomerRepositoryInterface $customerRepository
@@ -125,8 +130,11 @@ private function getCustomerGroupId(): ?int
125130 if ($ userType === UserContextInterface::USER_TYPE_CUSTOMER ) {
126131 $ customerId = $ this ->userContext ->getUserId ();
127132 if ($ customerId ) {
128- $ customer = $ this ->customerRepository ->getById ($ customerId );
129- return (int )$ customer ->getGroupId ();
133+ if (!isset ($ this ->customerGroupCache [$ customerId ])) {
134+ $ customer = $ this ->customerRepository ->getById ($ customerId );
135+ $ this ->customerGroupCache [$ customerId ] = (int )$ customer ->getGroupId ();
136+ }
137+ return $ this ->customerGroupCache [$ customerId ];
130138 }
131139 }
132140 // For guest users, return the not logged in group ID
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ class RetrieverPlugin
3535 */
3636 private $ appState ;
3737
38+ /**
39+ * @var array Cache for customer group IDs
40+ */
41+ private $ customerGroupCache = [];
42+
3843 /**
3944 * @param UserContextInterface $userContext
4045 * @param CustomerRepositoryInterface $customerRepository
@@ -72,9 +77,11 @@ public function aroundGetCustomerGroupId(
7277 if ($ userType === UserContextInterface::USER_TYPE_CUSTOMER ) {
7378 $ customerId = $ this ->userContext ->getUserId ();
7479 if ($ customerId ) {
75- $ customer = $ this ->customerRepository ->getById ($ customerId );
76- $ customerGroupId = (int )$ customer ->getGroupId ();
77- return $ customerGroupId ;
80+ if (!isset ($ this ->customerGroupCache [$ customerId ])) {
81+ $ customer = $ this ->customerRepository ->getById ($ customerId );
82+ $ this ->customerGroupCache [$ customerId ] = (int )$ customer ->getGroupId ();
83+ }
84+ return $ this ->customerGroupCache [$ customerId ];
7885 }
7986 }
8087 return Group::NOT_LOGGED_IN_ID ;
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ class SessionPlugin
3535 */
3636 private $ appState ;
3737
38+ /**
39+ * @var array Cache for customer group IDs
40+ */
41+ private $ customerGroupCache = [];
42+
3843 /**
3944 * @param UserContextInterface $userContext
4045 * @param CustomerRepositoryInterface $customerRepository
@@ -71,9 +76,11 @@ public function aroundGetCustomerGroupId(
7176 if ($ userType === UserContextInterface::USER_TYPE_CUSTOMER ) {
7277 $ customerId = $ this ->userContext ->getUserId ();
7378 if ($ customerId ) {
74- $ customer = $ this ->customerRepository ->getById ($ customerId );
75- $ customerGroupId = (int )$ customer ->getGroupId ();
76- return $ customerGroupId ;
79+ if (!isset ($ this ->customerGroupCache [$ customerId ])) {
80+ $ customer = $ this ->customerRepository ->getById ($ customerId );
81+ $ this ->customerGroupCache [$ customerId ] = (int )$ customer ->getGroupId ();
82+ }
83+ return $ this ->customerGroupCache [$ customerId ];
7784 }
7885 }
7986 return Group::NOT_LOGGED_IN_ID ;
You can’t perform that action at this time.
0 commit comments