Skip to content

Commit b7e9c0d

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4211' into PR_2025_09_19_flowers
2 parents eb94945 + 777c391 commit b7e9c0d

File tree

3 files changed

+53
-34
lines changed

3 files changed

+53
-34
lines changed

dev/tests/integration/testsuite/Magento/Framework/Mview/View/ChangelogTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testGetVersion()
112112
*/
113113
public function testChangelogClearOversizeBatchSize()
114114
{
115-
$stateVersionId = 10100;
115+
$stateVersionId = 14001;
116116
$changelog = $this->generateChangelog(20000);
117117

118118
// #0: check if changelog generated correctly
@@ -121,18 +121,12 @@ public function testChangelogClearOversizeBatchSize()
121121

122122
// #1: check if changelog reduced by batch size value
123123
$this->model->clear($stateVersionId);
124-
$this->assertEquals(10001, $this->getChangelogFirstEntityId($changelog));
125-
$this->assertEquals(10000, $this->getChangelogEntitiesCount($changelog));
124+
$this->assertEquals($stateVersionId, $this->getChangelogFirstEntityId($changelog));
125+
$this->assertEquals(6000, $this->getChangelogEntitiesCount($changelog));
126126

127-
// #2: check if changelog reduced to the mview state version id
128-
$this->model->clear($stateVersionId);
129-
$this->assertEquals(10100, $this->getChangelogFirstEntityId($changelog));
130-
$this->assertEquals(9901, $this->getChangelogEntitiesCount($changelog));
131-
132-
// #3: check if changelog stays the same size and values on the next iteration
133-
$this->model->clear($stateVersionId);
134-
$this->assertEquals(10100, $this->getChangelogFirstEntityId($changelog));
135-
$this->assertEquals(9901, $this->getChangelogEntitiesCount($changelog));
127+
// #2: fully clear changelog
128+
$this->model->clear(20001);
129+
$this->assertEquals(0, $this->getChangelogEntitiesCount($changelog));
136130
}
137131

138132
/**

lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -15,6 +15,7 @@
1515
use Magento\Framework\Mview\View\AdditionalColumnsProcessor\ProcessorFactory;
1616
use Magento\Framework\Mview\View\Changelog;
1717
use Magento\Framework\Mview\View\ChangelogInterface;
18+
use Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table as DtoFactoriesTable;
1819
use PHPUnit\Framework\MockObject\MockObject;
1920
use PHPUnit\Framework\TestCase;
2021

@@ -28,33 +29,44 @@ class ChangelogTest extends TestCase
2829
/**
2930
* @var Changelog
3031
*/
31-
protected $model;
32+
private $model;
3233

3334
/**
3435
* Mysql PDO DB adapter mock
3536
*
36-
* @var MockObject|\Magento\Framework\DB\Adapter\Pdo\Mysql
37+
* @var MockObject|Mysql
3738
*/
38-
protected $connectionMock;
39+
private $connectionMock;
3940

4041
/**
4142
* @var MockObject|ResourceConnection
4243
*/
43-
protected $resourceMock;
44+
private $resourceMock;
4445

4546
/**
4647
* @var ProcessorFactory|MockObject
4748
*/
48-
protected $processorFactory;
49+
private $processorFactory;
50+
51+
/**
52+
* @var DtoFactoriesTable|MockObject
53+
*/
54+
private $dtoFactoriesTableMock;
4955

5056
protected function setUp(): void
5157
{
5258
$this->connectionMock = $this->createMock(Mysql::class);
5359
$this->resourceMock = $this->createMock(ResourceConnection::class);
5460
$this->mockGetConnection($this->connectionMock);
5561
$this->processorFactory = $this->createMock(ProcessorFactory::class);
62+
$this->dtoFactoriesTableMock = $this->createMock(DtoFactoriesTable::class);
5663

57-
$this->model = new Changelog($this->resourceMock, $this->getMviewConfigMock(), $this->processorFactory);
64+
$this->model = new Changelog(
65+
$this->resourceMock,
66+
$this->getMviewConfigMock(),
67+
$this->processorFactory,
68+
$this->dtoFactoriesTableMock,
69+
);
5870
}
5971

6072
/**
@@ -73,11 +85,7 @@ private function getMviewConfigMock()
7385

7486
public function testInstanceOf()
7587
{
76-
$resourceMock =
77-
$this->createMock(ResourceConnection::class);
78-
$resourceMock->expects($this->once())->method('getConnection')->willReturn(true);
79-
$model = new Changelog($resourceMock, $this->getMviewConfigMock(), $this->processorFactory);
80-
$this->assertInstanceOf(ChangelogInterface::class, $model);
88+
$this->assertInstanceOf(ChangelogInterface::class, $this->model);
8189
}
8290

8391
public function testCheckConnectionException()
@@ -308,6 +316,21 @@ public function testGetListWithException()
308316
$this->model->getList(random_int(1, 200), random_int(201, 400));
309317
}
310318

319+
public function testClear()
320+
{
321+
$versionId = 100;
322+
$tableName = 'viewIdtest_cl';
323+
$this->resourceMock->expects(self::once())->method('getTableName')->willReturn($tableName);
324+
$this->connectionMock->expects(self::once())->method('isTableExists')->with($tableName)->willReturn(true);
325+
326+
$stmtMock = $this->createMock(\Zend_Db_Statement_Interface::class);
327+
$stmtMock->expects(self::exactly(3))->method('rowCount')->willReturnOnConsecutiveCalls(10000, 5000, 0);
328+
$this->connectionMock->expects(self::exactly(3))->method('query')->willReturn($stmtMock);
329+
330+
$this->model->setViewId('viewIdtest');
331+
$this->model->clear($versionId);
332+
}
333+
311334
public function testClearWithException()
312335
{
313336
$changelogTableName = 'viewIdtest_cl';

lib/internal/Magento/Framework/Mview/View/Changelog.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\DB\Adapter\ConnectionException;
11-
use Magento\Framework\DB\Sql\Expression;
1211
use Magento\Framework\Exception\RuntimeException;
1312
use Magento\Framework\Mview\Config;
1413
use Magento\Framework\Mview\View\AdditionalColumnsProcessor\ProcessorFactory;
@@ -86,13 +85,15 @@ class Changelog implements ChangelogInterface
8685
* @param Config $mviewConfig
8786
* @param ProcessorFactory $additionalColumnsProcessorFactory
8887
* @param DtoFactoriesTable|null $dtoFactoriesTable
88+
* @param int $batchSize
8989
* @throws ConnectionException
9090
*/
9191
public function __construct(
9292
\Magento\Framework\App\ResourceConnection $resource,
9393
Config $mviewConfig,
9494
ProcessorFactory $additionalColumnsProcessorFactory,
95-
?DtoFactoriesTable $dtoFactoriesTable = null
95+
?DtoFactoriesTable $dtoFactoriesTable = null,
96+
private readonly int $batchSize = self::CHANGELOG_CLEAR_BATCH_SIZE,
9697
) {
9798
$this->connection = $resource->getConnection();
9899
$this->resource = $resource;
@@ -254,14 +255,15 @@ public function clear($versionId)
254255
throw new ChangelogTableNotExistsException(new Phrase("Table %1 does not exist", [$changelogTableName]));
255256
}
256257

257-
$this->connection->query(
258-
sprintf(
259-
'DELETE FROM `%s` WHERE %s LIMIT %d',
260-
$changelogTableName,
261-
'version_id < ' . (int) $versionId,
262-
self::CHANGELOG_CLEAR_BATCH_SIZE
263-
)
258+
$query = sprintf(
259+
'DELETE FROM `%s` WHERE %s LIMIT %d',
260+
$changelogTableName,
261+
'version_id < ' . (int) $versionId,
262+
$this->batchSize
264263
);
264+
do {
265+
$stmt = $this->connection->query($query);
266+
} while ($stmt->rowCount());
265267

266268
return true;
267269
}

0 commit comments

Comments
 (0)