Skip to content

Commit fa237ca

Browse files
committed
MAGETWO-53019: [Performance]: Unexpected calls are made if view product on storefront
1 parent 04795a6 commit fa237ca

File tree

3 files changed

+13
-123
lines changed

3 files changed

+13
-123
lines changed

app/code/Magento/Customer/Controller/Account/UpdateSession.php

Lines changed: 0 additions & 77 deletions
This file was deleted.

app/code/Magento/Customer/Model/Plugin/CustomerNotification.php

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
use Magento\Framework\App\RequestInterface;
1313
use Magento\Framework\App\Response\Http;
1414
use Magento\Framework\App\State;
15-
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
16-
use Magento\Framework\Stdlib\CookieManagerInterface;
15+
use Magento\Customer\Api\CustomerRepositoryInterface;
1716

1817
class CustomerNotification
1918
{
@@ -28,16 +27,9 @@ class CustomerNotification
2827
private $notificationStorage;
2928

3029
/**
31-
* Cookie Manager
32-
*
33-
* @var \Magento\Framework\Stdlib\CookieManagerInterface
30+
* @var CustomerRepositoryInterface
3431
*/
35-
private $cookieManager;
36-
37-
/**
38-
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
39-
*/
40-
private $cookieMetadataFactory;
32+
private $customerRepository;
4133

4234
/**
4335
* @var State
@@ -49,22 +41,18 @@ class CustomerNotification
4941
*
5042
* @param Session $session
5143
* @param NotificationStorage $notificationStorage
52-
* @param CookieManagerInterface $cookieManager
53-
* @param CookieMetadataFactory $cookieMetadataFactory
5444
* @param State $state
5545
*/
5646
public function __construct(
5747
Session $session,
5848
NotificationStorage $notificationStorage,
59-
CookieManagerInterface $cookieManager,
60-
CookieMetadataFactory $cookieMetadataFactory,
61-
State $state
49+
State $state,
50+
CustomerRepositoryInterface $customerRepository
6251
) {
6352
$this->session = $session;
6453
$this->notificationStorage = $notificationStorage;
65-
$this->cookieManager = $cookieManager;
66-
$this->cookieMetadataFactory = $cookieMetadataFactory;
6754
$this->state = $state;
55+
$this->customerRepository = $customerRepository;
6856
}
6957

7058
/**
@@ -75,24 +63,17 @@ public function __construct(
7563
*/
7664
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
7765
{
78-
if ($this->state->getAreaCode() == Area::AREA_FRONTEND
66+
if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost()
7967
&& $this->notificationStorage->isExists(
8068
NotificationStorage::UPDATE_CUSTOMER_SESSION,
8169
$this->session->getCustomerId()
8270
)
8371
) {
84-
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
85-
$publicCookieMetadata->setDurationOneYear();
86-
$publicCookieMetadata->setPath('/');
87-
$publicCookieMetadata->setHttpOnly(false);
88-
$this->cookieManager->setPublicCookie(
89-
NotificationStorage::UPDATE_CUSTOMER_SESSION,
90-
$this->session->getCustomerId(),
91-
$publicCookieMetadata
92-
);
93-
94-
$cookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
95-
$this->cookieManager->deleteCookie(Http::COOKIE_VARY_STRING, $cookieMetadata);
72+
$customer = $this->customerRepository->getById($this->session->getCustomerId());
73+
$this->session->setCustomerData($customer);
74+
$this->session->setCustomerGroupId($customer->getGroupId());
75+
$this->session->regenerateId();
76+
$this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
9677
}
9778
}
9879
}

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,7 @@ define([
188188
*/
189189
init: function() {
190190
var countryData,
191-
privateContent = $.cookieStorage.get('private_content_version'),
192-
updateSession = $.cookieStorage.get('update_customer_session');
193-
if (updateSession) {
194-
mageStorage.post(
195-
options.updateSessionUrl,
196-
JSON.stringify({
197-
'customer_id': updateSession,
198-
'form_key': window.FORM_KEY
199-
})
200-
).done(
201-
function () {
202-
$.cookieStorage.setConf({path: '/', expires: -1}).set('update_customer_session', null);
203-
}
204-
);
205-
}
191+
privateContent = $.cookieStorage.get('private_content_version');
206192

207193
if (_.isEmpty(storage.keys())) {
208194
if (!_.isEmpty(privateContent)) {

0 commit comments

Comments
 (0)