Skip to content

Commit 10c9331

Browse files
ENGCOM-8237: Prevent flushing same tags several times #29885
- Merge Pull Request #29885 from siimm/magento2:2.4-latest - Merged commits: 1. 256cedd 2. f17148f 3. 47761ec 4. 2844fbf
2 parents 3c3c8ed + 2844fbf commit 10c9331

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/internal/Magento/Framework/Indexer/CacheContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ public function getIdentities()
7373
$identities[] = $cacheTag . '_' . $id;
7474
}
7575
}
76-
return array_merge($identities, array_unique($this->tags));
76+
return array_unique(array_merge($identities, array_unique($this->tags)));
7777
}
7878
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\Indexer\Test\Unit;
10+
11+
use Magento\Framework\Indexer\CacheContext;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class CacheContextTest extends TestCase
15+
{
16+
/**
17+
* @var Batch
18+
*/
19+
private $object;
20+
21+
protected function setUp(): void
22+
{
23+
$this->object = new CacheContext();
24+
}
25+
26+
/**
27+
* @param array $tagsData
28+
* @param array $expected
29+
* @dataProvider getTagsDataProvider
30+
*/
31+
public function testUniqueTags($tagsData, $expected)
32+
{
33+
foreach ($tagsData as $tagSet) {
34+
foreach ($tagSet as $cacheTag => $ids) {
35+
$this->object->registerEntities($cacheTag, $ids);
36+
}
37+
}
38+
39+
$this->assertEquals($this->object->getIdentities(), $expected);
40+
}
41+
42+
/**
43+
* @return array
44+
*/
45+
public function getTagsDataProvider()
46+
{
47+
return [
48+
'same entities and ids' => [
49+
[['cat_p' => [1]], ['cat_p' => [1]]],
50+
['cat_p_1']
51+
],
52+
'same entities with overlapping ids' => [
53+
[['cat_p' => [1, 2, 3]], ['cat_p' => [3]]],
54+
['cat_p_1', 'cat_p_2', 'cat_p_3']
55+
]
56+
];
57+
}
58+
}

0 commit comments

Comments
 (0)