|
| 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 | +} |
0 commit comments