Skip to content

Commit 392730c

Browse files
committed
Initial commit
0 parents  commit 392730c

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace IntegerNet\SectionsDataSessionUnblocker\Plugin;
5+
6+
use \Magento\Framework\Session\Generic as GenericSession;
7+
use \Magento\Customer\Model\Session as CustomerSession;
8+
use \Magento\Framework\Message\Session as MessageSession;
9+
use \Magento\Catalog\Model\Session as CatalogSession;
10+
11+
/*
12+
* We are writing this plugin to make sure sessions are all loaded before
13+
* Magento\Customer\Controller\Section\Load
14+
*
15+
* Right after initiating all the needed Sessions we close the session,
16+
* since we're only reading from the session when requesting sectionData
17+
* in the frontend.
18+
*
19+
* This means every sectionPool that is being loaded does not need to read
20+
* from an open session, which means calls to SectionLoad controller are
21+
* no longer blocking each other because they are waiting for the request to
22+
* finish and the close the session.
23+
*/
24+
class SectionLoadControllerPlugin
25+
{
26+
/**
27+
* @param GenericSession $genericSession
28+
* @param CustomerSession $customerSession
29+
* @param MessageSession $messageSession
30+
* @param CatalogSession $catalogSession
31+
* @param GenericSession $reviewSession
32+
*
33+
* Disabling 3 PHPCS rules because:
34+
* 1 - We are well aware that we normally shouldn't call Sessions without
35+
* proxy, but in this case, we actually want the sessions to be
36+
* initiated directly.
37+
* 2 - Also, we don't actually use the Sessions
38+
* 3 - Lastly, we normally should not execute operations in a constructor
39+
*
40+
* phpcs:disable MEQP2.Classes.MutableObjects.MutableObjects
41+
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found
42+
* phpcs:disable MEQP2.Classes.ConstructorOperations.CustomOperationsFound
43+
*/
44+
public function __construct(
45+
GenericSession $genericSession,
46+
CustomerSession $customerSession,
47+
MessageSession $messageSession,
48+
CatalogSession $catalogSession,
49+
GenericSession $reviewSession //virtualType
50+
) {
51+
/*
52+
* This is earliest moment where we can close the session,
53+
* after we initialised all sessions we think will be needed
54+
*
55+
* Should there ever be an additional Session-type that's needed,
56+
* nothing breaks, but the new session-type will open a new session
57+
* and therefore block other requests
58+
*/
59+
$genericSession->writeClose();
60+
}
61+
62+
//phpcs:ignore MEQP2.Classes.PublicNonInterfaceMethods.PublicMethodFound
63+
public function beforeExecute()
64+
{
65+
}
66+
}

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "integer-net/magento2-session-unblocker",
3+
"description": "Module for Magento 2 that prevents session blocking between concurrent AJAX requests",
4+
"version": "0.0.1",
5+
"authors": [
6+
{
7+
"name": "Fabian Schmengler",
8+
"email": "fs@integer-net.de"
9+
},
10+
{
11+
"name": "Willem Wigman",
12+
"email": "ww@integer-net.de"
13+
}
14+
],
15+
"require": {
16+
"magento/framework": "^100.1|^101.0|^102.0",
17+
"magento/module-customer": "^101.0.0|^102.0.0",
18+
"magento/module-catalog": "^101.0.0|^102.0.0",
19+
"php": ">=7.0.0"
20+
},
21+
"type": "magento2-module",
22+
"license": [
23+
"OSL-3"
24+
],
25+
"autoload": {
26+
"files": [
27+
"registration.php"
28+
],
29+
"psr-4": {
30+
"IntegerNet\\SessionUnblocker\\": ""
31+
}
32+
}
33+
}

etc/di.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<type name="Magento\Customer\Controller\Section\Load">
4+
<plugin name="integernet_session_unblocker" type="IntegerNet\SessionUnblocker\Plugin\SectionLoadControllerPlugin" />
5+
</type>
6+
7+
<type name="IntegerNet\SessionUnblocker\Plugin\SectionLoadControllerPlugin">
8+
<arguments>
9+
<argument name="reviewSession" xsi:type="object">Magento\Review\Model\Session</argument>
10+
</arguments>
11+
</type>
12+
</config>

etc/module.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4+
<module name="IntegerNet_SectionsDataSessionUnblocker" setup_version="0.0.1">
5+
<sequence>
6+
<module name="Magento_Customer"/>
7+
</sequence>
8+
</module>
9+
</config>

registration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
\Magento\Framework\Component\ComponentRegistrar::register(
3+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
4+
'IntegerNet_SessionUnblocker',
5+
__DIR__
6+
);

0 commit comments

Comments
 (0)