Skip to content

Commit 20f947f

Browse files
committed
ACP2E-3493: addressed CR comment
1 parent 9ddc60d commit 20f947f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

app/code/Magento/Persistent/Model/CleanExpiredPersistentQuotes.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ class CleanExpiredPersistentQuotes
2727
* @param QuoteRepository $quoteRepository
2828
* @param Snapshot $snapshot
2929
* @param LoggerInterface $logger
30+
* @param int $batchSize
3031
*/
3132
public function __construct(
3233
private readonly StoreManagerInterface $storeManager,
3334
private readonly ExpiredPersistentQuotesCollection $expiredPersistentQuotesCollection,
3435
private readonly QuoteRepository $quoteRepository,
35-
private Snapshot $snapshot,
36-
private readonly LoggerInterface $logger
36+
private readonly Snapshot $snapshot,
37+
private readonly LoggerInterface $logger,
38+
private readonly int $batchSize
3739
) {
3840
}
3941

@@ -60,12 +62,11 @@ public function execute(int $websiteId): void
6062
*/
6163
private function processStoreQuotes(StoreInterface $store): void
6264
{
63-
$batchSize = 500;
6465
$lastProcessedId = $count = 0;
6566

6667
while (true) {
6768
$quotesToProcess = $this->expiredPersistentQuotesCollection
68-
->getExpiredPersistentQuotes($store, $lastProcessedId, $batchSize);
69+
->getExpiredPersistentQuotes($store, $lastProcessedId, $this->batchSize);
6970

7071
if (!$quotesToProcess->count()) {
7172
break;
@@ -83,7 +84,7 @@ private function processStoreQuotes(StoreInterface $store): void
8384
(string)$e
8485
));
8586
}
86-
if ($count % $batchSize === 0) {
87+
if ($count % $this->batchSize === 0) {
8788
$this->snapshot->clear($quote);
8889
}
8990
$quote->clearInstance();

app/code/Magento/Persistent/Test/Unit/Model/CleanExpiredPersistentQuotesTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,24 @@ class CleanExpiredPersistentQuotesTest extends TestCase
5757
*/
5858
private CleanExpiredPersistentQuotes $cleanExpiredPersistentQuotes;
5959

60+
private int $batchSize;
61+
6062
protected function setUp(): void
6163
{
6264
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
6365
$this->expiredPersistentQuotesCollectionMock = $this->createMock(ExpiredPersistentQuotesCollection::class);
6466
$this->quoteRepositoryMock = $this->createMock(QuoteRepository::class);
6567
$this->snapshotMock = $this->createMock(Snapshot::class);
6668
$this->loggerMock = $this->createMock(LoggerInterface::class);
69+
$this->batchSize = 500;
6770

6871
$this->cleanExpiredPersistentQuotes = new CleanExpiredPersistentQuotes(
6972
$this->storeManagerMock,
7073
$this->expiredPersistentQuotesCollectionMock,
7174
$this->quoteRepositoryMock,
7275
$this->snapshotMock,
73-
$this->loggerMock
76+
$this->loggerMock,
77+
$this->batchSize
7478
);
7579
}
7680

app/code/Magento/Persistent/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
<type name="Magento\Quote\Model\QuoteManagement">
2626
<plugin name="persistent_convert_customer_cart_to_guest_cart" type="Magento\Persistent\Model\Plugin\ConvertCustomerCartToGuest" />
2727
</type>
28+
<type name="Magento\Persistent\Model\CleanExpiredPersistentQuotes">
29+
<arguments>
30+
<argument name="batchSize" xsi:type="number">500</argument>
31+
</arguments>
32+
</type>
2833
</config>

0 commit comments

Comments
 (0)