-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding all files to git via Yireo Command
- Loading branch information
0 parents
commit 4127ce8
Showing
6 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Yireo\MagewireRouter\Controller; | ||
|
||
use Magento\Framework\App\Request\Http; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\App\RouterInterface; | ||
use Magewirephp\Magewire\Controller\Post\LivewireFactory as ControllerFactory; | ||
|
||
class Router implements RouterInterface | ||
{ | ||
public function __construct( | ||
private ControllerFactory $controllerFactory, | ||
) { | ||
} | ||
|
||
public function match(RequestInterface $request) | ||
{ | ||
/** @var Http $request */ | ||
if (false === strstr($request->getRequestUri(), 'magewire/post/livewire')) { | ||
return false; | ||
} | ||
|
||
$request->setControllerModule('magewire'); | ||
$request->setModuleName('post'); | ||
$request->setActionName('livewire'); | ||
$request->setDispatched(true); | ||
|
||
return $this->controllerFactory->create(); | ||
} | ||
} |
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,14 @@ | ||
# Yireo MagewireRouter | ||
|
||
**This Magento 2 module adds a router specifically for Magewire requests, shaving off various milliseconds off every request.** | ||
|
||
## Reasoning | ||
By default, when a request to `magewire/post/livewire` is made, it loops through routers before hitting the `standard` router which maps the URL path to the right controller. This means that with every request, the `securitytxt` router, the `robots` router and the `urlrewrite` router are used. And the `urlrewrite` router adds an additional database query. This module adds a new router with ordering 1, preceeding all others. | ||
|
||
## Benchmarks | ||
Simple benchmarking with `time` and `curl` was used to determine the request time of Magewire with this module enabled and with this module disabled: | ||
```bash | ||
time curl -s -H 'Content-Type: application/json' -d '{}' -XPOST -S http://magento.local/default/magewire/post/livewire | ||
``` | ||
|
||
In my case, without the module, request times are between 165ms and 200ms. With the module enabled, request times are between 155ms and 180ms. |
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,20 @@ | ||
{ | ||
"name": "yireo/module-magewire-router", | ||
"version": "1.0.0", | ||
"description": "N/A", | ||
"type": "magento2-module", | ||
"require": { | ||
"magento/framework": "*" | ||
}, | ||
"license": [ | ||
"Open Software License (OSL)" | ||
], | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"Yireo\\MagewireRouter\\": "" | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Framework\App\RouterList"> | ||
<arguments> | ||
<argument name="routerList" xsi:type="array"> | ||
<item name="magewire" xsi:type="array"> | ||
<item name="class" xsi:type="string">Yireo\MagewireRouter\Controller\Router</item> | ||
<item name="disable" xsi:type="boolean">false</item> | ||
<item name="sortOrder" xsi:type="string">1</item> | ||
</item> | ||
</argument> | ||
</arguments> | ||
</type> | ||
</config> |
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,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Yireo_MagewireRouter"> | ||
<sequence> | ||
<module name="Magewirephp_Magewire"/> | ||
</sequence> | ||
</module> | ||
</config> |
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,6 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Yireo_MagewireRouter', __DIR__); |