-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/module-elasticsuite-tracker/Plugin/SessionStartCheckerPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteTracker | ||
* @author Romain Ruaud <[email protected]> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteTracker\Plugin; | ||
|
||
use Magento\Framework\App\Request\Http; | ||
use Magento\Framework\Session\SessionStartChecker; | ||
|
||
/** | ||
* Prevent session creation when going through a tracker hit URL. | ||
* Session creation can have performance issues when several ajax calls are sent in parallel. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteTracker | ||
* @author Romain Ruaud <[email protected]> | ||
*/ | ||
class SessionStartCheckerPlugin | ||
{ | ||
/** | ||
* @var Http | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @param Http $request HTTP Request | ||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) | ||
*/ | ||
public function __construct( | ||
Http $request | ||
) { | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* Prevents session starting when going through a tracker hit URL. | ||
* | ||
* @param SessionStartChecker $subject Session start checker | ||
* @param bool $result Legacy result | ||
* | ||
* @return bool | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterCheck(SessionStartChecker $subject, bool $result): bool | ||
{ | ||
if ($result === false) { | ||
return false; | ||
} | ||
|
||
$requestPath = trim($this->request->getPathInfo(), '/'); | ||
|
||
if ($requestPath === 'elasticsuite/tracker/hit/image/h.png') { | ||
$result = false; | ||
} elseif ($requestPath === 'rest/V1/elasticsuite-tracker/hit') { | ||
$result = false; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters