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
49
49
*/
50
50
private $ logger ;
51
51
52
+ /**
53
+ * @var array Cache for customer group IDs
54
+ */
55
+ private $ customerGroupCache = [];
56
+
52
57
/**
53
58
* @param UserContextInterface $userContext
54
59
* @param CustomerRepositoryInterface $customerRepository
@@ -125,8 +130,11 @@ private function getCustomerGroupId(): ?int
125
130
if ($ userType === UserContextInterface::USER_TYPE_CUSTOMER ) {
126
131
$ customerId = $ this ->userContext ->getUserId ();
127
132
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 ];
130
138
}
131
139
}
132
140
// 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
35
35
*/
36
36
private $ appState ;
37
37
38
+ /**
39
+ * @var array Cache for customer group IDs
40
+ */
41
+ private $ customerGroupCache = [];
42
+
38
43
/**
39
44
* @param UserContextInterface $userContext
40
45
* @param CustomerRepositoryInterface $customerRepository
@@ -72,9 +77,11 @@ public function aroundGetCustomerGroupId(
72
77
if ($ userType === UserContextInterface::USER_TYPE_CUSTOMER ) {
73
78
$ customerId = $ this ->userContext ->getUserId ();
74
79
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 ];
78
85
}
79
86
}
80
87
return Group::NOT_LOGGED_IN_ID ;
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ class SessionPlugin
35
35
*/
36
36
private $ appState ;
37
37
38
+ /**
39
+ * @var array Cache for customer group IDs
40
+ */
41
+ private $ customerGroupCache = [];
42
+
38
43
/**
39
44
* @param UserContextInterface $userContext
40
45
* @param CustomerRepositoryInterface $customerRepository
@@ -71,9 +76,11 @@ public function aroundGetCustomerGroupId(
71
76
if ($ userType === UserContextInterface::USER_TYPE_CUSTOMER ) {
72
77
$ customerId = $ this ->userContext ->getUserId ();
73
78
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 ];
77
84
}
78
85
}
79
86
return Group::NOT_LOGGED_IN_ID ;
You can’t perform that action at this time.
0 commit comments