File tree Expand file tree Collapse file tree 8 files changed +193
-1
lines changed
Expand file tree Collapse file tree 8 files changed +193
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Comwrap \WebapiAsyncObjectValidation \Model ;
6+
7+ use Magento \Framework \App \Request \Http as HttpRequest ;
8+
9+ class Config
10+ {
11+ public const BULK_PROCESSOR_PATH_REGEXP = "/\/async\/bulk( \\/V.+)/ " ;
12+ public const ARRAY_MODE_HEADER_KEY = 'disable-object-validation ' ;
13+
14+ /** @var HttpRequest */
15+ private HttpRequest $ request ;
16+
17+ /** @var null|bool */
18+ private ?bool $ isArrayMode = null ;
19+
20+ /**
21+ * @param HttpRequest $request
22+ */
23+ public function __construct (HttpRequest $ request )
24+ {
25+ $ this ->request = $ request ;
26+ }
27+
28+ /**
29+ * Check if is bulk api request and header is set
30+ *
31+ * @return bool
32+ */
33+ public function isPublishingArrayMode (): bool
34+ {
35+ if ($ this ->isArrayMode === null ) {
36+ $ this ->isArrayMode =
37+ $ this ->isBulkApiRequest () && $ this ->request ->getHeader (self ::ARRAY_MODE_HEADER_KEY );
38+ }
39+ return $ this ->isArrayMode ;
40+ }
41+
42+ /**
43+ * Check if current request is bulk
44+ *
45+ * @return bool
46+ */
47+ public function isBulkApiRequest (): bool
48+ {
49+ return (bool )preg_match (self ::BULK_PROCESSOR_PATH_REGEXP , $ this ->request ->getPathInfo ());
50+ }
51+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Comwrap \WebapiAsyncObjectValidation \Plugin \Magento \Framework \MessageQueue ;
6+
7+ use Comwrap \WebapiAsyncObjectValidation \Model \Config ;
8+ use Magento \Framework \MessageQueue \MessageValidator as OriginMessageValidator ;
9+
10+ class MessageValidator
11+ {
12+ /** @var Config */
13+ private Config $ config ;
14+
15+ /**
16+ * @param Config $config
17+ */
18+ public function __construct (Config $ config )
19+ {
20+ $ this ->config = $ config ;
21+ }
22+
23+ /**
24+ * Skip validation if array mode is set
25+ *
26+ * @param OriginMessageValidator $subject
27+ * @param \Closure $proceed
28+ * @param mixed ...$args
29+ * @return void
30+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
31+ */
32+ public function aroundValidate (OriginMessageValidator $ subject , \Closure $ proceed , ...$ args ): void
33+ {
34+ if ($ this ->config ->isPublishingArrayMode ()) {
35+ return ;
36+ }
37+ $ proceed (...$ args );
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Comwrap \WebapiAsyncObjectValidation \Plugin \Magento \Framework \Webapi ;
6+
7+ use Comwrap \WebapiAsyncObjectValidation \Model \Config ;
8+ use Magento \Framework \Webapi \ServiceInputProcessor as OriginServiceInputProcessor ;
9+
10+ class ServiceInputProcessor
11+ {
12+ /** @var Config */
13+ private Config $ config ;
14+
15+ /**
16+ * @param Config $config
17+ */
18+ public function __construct (Config $ config )
19+ {
20+ $ this ->config = $ config ;
21+ }
22+
23+ /**
24+ * Return array if array mode is set
25+ *
26+ * @param OriginServiceInputProcessor $subject
27+ * @param \Closure $proceed
28+ * @param string $serviceClassName
29+ * @param string $serviceMethodName
30+ * @param array $inputArray
31+ * @return array
32+ */
33+ public function aroundProcess (
34+ OriginServiceInputProcessor $ subject ,
35+ \Closure $ proceed ,
36+ string $ serviceClassName ,
37+ string $ serviceMethodName ,
38+ array $ inputArray
39+ ): array
40+ {
41+ if ($ this ->config ->isPublishingArrayMode ()) {
42+ return [];
43+ }
44+ return $ proceed ($ serviceClassName , $ serviceMethodName , $ inputArray );
45+ }
46+ }
Original file line number Diff line number Diff line change 1- # Comwrap_WebapiAsyncObjectValidation
1+ # Comwrap_WebapiAsyncObjectValidation
2+
3+ Increase Bulk API performance, using direct entity publishing as array without creating objects for validation.
4+
5+ ## How to use
6+
7+ Extension works for API request to the Bulk API endpoints. Set the custom request header with name 'disable-object-validation'.
8+ Value for a header could be any, even empty. If header is set, the extension skips objects creation and validation.
9+ These operations take quite long time among the request duration.
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " comwrap/module-webapi-async-object-validation" ,
3+ "version" : " 0.1.0" ,
4+ "description" : " Increase Bulk API performance, using direct entity publishing as array without creating objects for validation" ,
5+ "type" : " magento2-module" ,
6+ "require" : {
7+ "magento/framework" : " ^103"
8+ },
9+ "license" : [
10+ " Proprietary"
11+ ],
12+ "autoload" : {
13+ "files" : [
14+ " registration.php"
15+ ],
16+ "psr-4" : {
17+ "Comwrap\\ WebapiAsyncObjectValidation\\ " : " "
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change 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 =" Comwrap_WebapiAsyncObjectValidation" >
5+ <sequence >
6+ <module name =" Magento_WebapiAsync" />
7+ </sequence >
8+ </module >
9+ </config >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xsi : noNamespaceSchemaLocation =" urn:magento:framework:ObjectManager/etc/config.xsd" >
4+ <type name =" Magento\Framework\MessageQueue\MessageValidator" >
5+ <plugin name =" comwrapWebapiAsyncObjectValidationPluginMagentoFrameworkMessageQueueMessageValidator"
6+ type =" Comwrap\WebapiAsyncObjectValidation\Plugin\Magento\Framework\MessageQueue\MessageValidator" />
7+ </type >
8+ <type name =" Magento\Framework\Webapi\ServiceInputProcessor" >
9+ <plugin name =" comwrapWebapiAsyncObjectValidationPluginMagentoFrameworkWebapiServiceInputProcessor"
10+ type =" Comwrap\WebapiAsyncObjectValidation\Plugin\Magento\Framework\Webapi\ServiceInputProcessor" />
11+ </type >
12+ </config >
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Magento \Framework \Component \ComponentRegistrar ;
6+
7+ ComponentRegistrar::register (ComponentRegistrar::MODULE , 'Comwrap_WebapiAsyncObjectValidation ' , __DIR__ );
You can’t perform that action at this time.
0 commit comments