-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FRW-9739 Adjusted DDE API performance. (#11273)
FRW-9739 Adjusted DDE API performance.
- Loading branch information
1 parent
d4bd24d
commit f735e0e
Showing
13 changed files
with
403 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
49 changes: 49 additions & 0 deletions
49
src/Spryker/Zed/Url/Business/BulkCreator/UrlBulkCreator.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,49 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Url\Business\BulkCreator; | ||
|
||
use Spryker\Zed\Url\Persistence\UrlEntityManagerInterface; | ||
|
||
class UrlBulkCreator implements UrlBulkCreatorInterface | ||
{ | ||
/** | ||
* @param array<\Spryker\Zed\Url\Business\Url\UrlCreatorBeforeSaveObserverInterface> $createBeforeSaveObservers | ||
* @param array<\Spryker\Zed\Url\Business\Url\UrlCreatorAfterSaveObserverInterface> $createAfterSaveObservers | ||
* @param \Spryker\Zed\Url\Persistence\UrlEntityManagerInterface $urlEntityManager | ||
*/ | ||
public function __construct( | ||
protected array $createBeforeSaveObservers, | ||
protected array $createAfterSaveObservers, | ||
protected UrlEntityManagerInterface $urlEntityManager | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<\Generated\Shared\Transfer\UrlTransfer> | ||
*/ | ||
public function create(array $urlTransfers): array | ||
{ | ||
foreach ($urlTransfers as $urlTransfer) { | ||
foreach ($this->createBeforeSaveObservers as $observer) { | ||
$observer->handleUrlCreation($urlTransfer); | ||
} | ||
} | ||
|
||
$this->urlEntityManager->saveUrlEntities($urlTransfers); | ||
|
||
foreach ($urlTransfers as $urlTransfer) { | ||
foreach ($this->createAfterSaveObservers as $observer) { | ||
$observer->handleUrlCreation($urlTransfer); | ||
} | ||
} | ||
|
||
return $urlTransfers; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Spryker/Zed/Url/Business/BulkCreator/UrlBulkCreatorInterface.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,18 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Url\Business\BulkCreator; | ||
|
||
interface UrlBulkCreatorInterface | ||
{ | ||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<\Generated\Shared\Transfer\UrlTransfer> | ||
*/ | ||
public function create(array $urlTransfers): array; | ||
} |
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,60 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Url\Business\BulkSaver; | ||
|
||
use Spryker\Zed\Url\Business\BulkCreator\UrlBulkCreatorInterface; | ||
use Spryker\Zed\Url\Business\BulkUpdater\UrlBulkUpdaterInterface; | ||
|
||
class UrlBulkSaver implements UrlBulkSaverInterface | ||
{ | ||
/** | ||
* @param \Spryker\Zed\Url\Business\BulkCreator\UrlBulkCreatorInterface $urlBulkCreator | ||
* @param \Spryker\Zed\Url\Business\BulkUpdater\UrlBulkUpdaterInterface $urlBulkUpdater | ||
*/ | ||
public function __construct( | ||
protected UrlBulkCreatorInterface $urlBulkCreator, | ||
protected UrlBulkUpdaterInterface $urlBulkUpdater | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<\Generated\Shared\Transfer\UrlTransfer> | ||
*/ | ||
public function save(array $urlTransfers): array | ||
{ | ||
[$newUrlTransfers, $existingUrlTransfers] = $this->separateNewTransferFromExisting($urlTransfers); | ||
|
||
$urlTransfers = $this->urlBulkCreator->create($newUrlTransfers); | ||
|
||
return array_merge($urlTransfers, $this->urlBulkUpdater->update($existingUrlTransfers)); | ||
} | ||
|
||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<array<\Generated\Shared\Transfer\UrlTransfer>> | ||
*/ | ||
protected function separateNewTransferFromExisting(array $urlTransfers): array | ||
{ | ||
$newUrlTransfers = []; | ||
$existingUrlTransfers = []; | ||
|
||
foreach ($urlTransfers as $urlTransfer) { | ||
if ($urlTransfer->getIdUrl() === null) { | ||
$newUrlTransfers[] = $urlTransfer; | ||
|
||
continue; | ||
} | ||
$existingUrlTransfers[] = $urlTransfer; | ||
} | ||
|
||
return [$newUrlTransfers, $existingUrlTransfers]; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Spryker/Zed/Url/Business/BulkSaver/UrlBulkSaverInterface.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,18 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Url\Business\BulkSaver; | ||
|
||
interface UrlBulkSaverInterface | ||
{ | ||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<\Generated\Shared\Transfer\UrlTransfer> | ||
*/ | ||
public function save(array $urlTransfers): array; | ||
} |
100 changes: 100 additions & 0 deletions
100
src/Spryker/Zed/Url/Business/BulkUpdater/UrlBulkUpdater.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,100 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Url\Business\BulkUpdater; | ||
|
||
use Generated\Shared\Transfer\UrlTransfer; | ||
use Spryker\Zed\Url\Business\Url\UrlReaderInterface; | ||
use Spryker\Zed\Url\Persistence\UrlEntityManagerInterface; | ||
|
||
class UrlBulkUpdater implements UrlBulkUpdaterInterface | ||
{ | ||
/** | ||
* @param \Spryker\Zed\Url\Business\Url\UrlReaderInterface $urlReader | ||
* @param array<\Spryker\Zed\Url\Business\Url\UrlUpdaterBeforeSaveObserverInterface> $updateBeforeSaveObservers | ||
* @param array<\Spryker\Zed\Url\Business\Url\UrlUpdaterAfterSaveObserverInterface> $updateAfterSaveObservers | ||
* @param \Spryker\Zed\Url\Persistence\UrlEntityManagerInterface $urlEntityManager | ||
*/ | ||
public function __construct( | ||
protected UrlReaderInterface $urlReader, | ||
protected array $updateBeforeSaveObservers, | ||
protected array $updateAfterSaveObservers, | ||
protected UrlEntityManagerInterface $urlEntityManager | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<\Generated\Shared\Transfer\UrlTransfer> | ||
*/ | ||
public function update(array $urlTransfers): array | ||
{ | ||
[$urlTransfers, $originalTransfers] = $this->filterExistingUrlTransfers($urlTransfers); | ||
|
||
foreach ($urlTransfers as $urlTransfer) { | ||
$this->notifyUpdateBeforeSaveObservers($urlTransfer, $originalTransfers[$urlTransfer->getIdUrl()]); | ||
} | ||
|
||
$this->urlEntityManager->saveUrlEntities($urlTransfers, false); | ||
|
||
foreach ($urlTransfers as $urlTransfer) { | ||
$this->notifyUpdateAfterSaveObservers($urlTransfer, $originalTransfers[$urlTransfer->getIdUrl()]); | ||
} | ||
|
||
return $urlTransfers; | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\UrlTransfer $urlTransfer | ||
* @param \Generated\Shared\Transfer\UrlTransfer $originalTransfer | ||
* | ||
* @return void | ||
*/ | ||
protected function notifyUpdateBeforeSaveObservers(UrlTransfer $urlTransfer, UrlTransfer $originalTransfer): void | ||
{ | ||
foreach ($this->updateBeforeSaveObservers as $observer) { | ||
$observer->handleUrlUpdate($urlTransfer, $originalTransfer); | ||
} | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\UrlTransfer $urlTransfer | ||
* @param \Generated\Shared\Transfer\UrlTransfer $originalTransfer | ||
* | ||
* @return void | ||
*/ | ||
protected function notifyUpdateAfterSaveObservers(UrlTransfer $urlTransfer, UrlTransfer $originalTransfer): void | ||
{ | ||
foreach ($this->updateAfterSaveObservers as $observer) { | ||
$observer->handleUrlUpdate($urlTransfer, $originalTransfer); | ||
} | ||
} | ||
|
||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<array<\Generated\Shared\Transfer\UrlTransfer>> | ||
*/ | ||
protected function filterExistingUrlTransfers(array $urlTransfers): array | ||
{ | ||
$filteredUrlTransfers = []; | ||
$originalTransfers = []; | ||
foreach ($urlTransfers as $urlTransfer) { | ||
if ($urlTransfer->getOriginalUrl() === $urlTransfer->getUrl() || $this->urlReader->hasUrl($urlTransfer)) { | ||
continue; | ||
} | ||
|
||
$filteredUrlTransfers[$urlTransfer->getIdUrl()] = $urlTransfer; | ||
$originalTransfer = clone $urlTransfer; | ||
$originalTransfer->setUrl($urlTransfer->getOriginalUrl()); | ||
$originalTransfers[$urlTransfer->getIdUrl()] = $originalTransfer; | ||
} | ||
|
||
return [$filteredUrlTransfers, $originalTransfers]; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Spryker/Zed/Url/Business/BulkUpdater/UrlBulkUpdaterInterface.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,18 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Url\Business\BulkUpdater; | ||
|
||
interface UrlBulkUpdaterInterface | ||
{ | ||
/** | ||
* @param array<\Generated\Shared\Transfer\UrlTransfer> $urlTransfers | ||
* | ||
* @return array<\Generated\Shared\Transfer\UrlTransfer> | ||
*/ | ||
public function update(array $urlTransfers): array; | ||
} |
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
Oops, something went wrong.