Skip to content

Commit 98eb658

Browse files
authored
ENGCOM-7974: Fix Replace nestead query with separate queries in the entity filter processor #29422
2 parents 6cb92ae + 5ab18d7 commit 98eb658

File tree

2 files changed

+32
-27
lines changed
  • app/code/Magento/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor

2 files changed

+32
-27
lines changed

app/code/Magento/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/Entity.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
1212
use Magento\Framework\App\ResourceConnection;
1313
use Magento\Framework\Data\Collection\AbstractDb;
14-
use Magento\Framework\DB\Select;
1514

1615
/**
1716
* Custom filter to filter collection by entity type
@@ -49,30 +48,36 @@ public function apply(Filter $filter, AbstractDb $collection): bool
4948
$ids = $filter->getValue();
5049
if (is_array($ids)) {
5150
$collection->addFieldToFilter(
52-
self::TABLE_ALIAS . '.id',
53-
['in' => $this->getSelectByEntityIds($ids)]
51+
[self::TABLE_ALIAS . '.id'],
52+
[
53+
['in' => $this->getSelectByEntityIds($ids)]
54+
]
5455
);
5556
}
5657
return true;
5758
}
5859

5960
/**
60-
* Return select asset ids by entity type
61+
* Return asset ids by entity type
6162
*
6263
* @param array $ids
63-
* @return Select
64+
* @return array
6465
*/
65-
private function getSelectByEntityIds(array $ids): Select
66+
private function getSelectByEntityIds(array $ids): array
6667
{
67-
return $this->connection->getConnection()->select()->from(
68-
['asset_content_table' => $this->connection->getTableName(self::TABLE_MEDIA_CONTENT_ASSET)],
69-
['asset_id']
70-
)->where(
71-
'entity_type = ?',
72-
$this->entityType
73-
)->where(
74-
'entity_id IN (?)',
75-
$ids
68+
$connection = $this->connection->getConnection();
69+
70+
return $connection->fetchAssoc(
71+
$connection->select()->from(
72+
['asset_content_table' => $this->connection->getTableName(self::TABLE_MEDIA_CONTENT_ASSET)],
73+
['asset_id']
74+
)->where(
75+
'entity_type = ?',
76+
$this->entityType
77+
)->where(
78+
'entity_id IN (?)',
79+
$ids
80+
)
7681
);
7782
}
7883
}

app/code/Magento/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/Keyword.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
1212
use Magento\Framework\App\ResourceConnection;
1313
use Magento\Framework\Data\Collection\AbstractDb;
14-
use Magento\Framework\DB\Select;
1514

1615
class Keyword implements CustomFilterInterface
1716
{
@@ -59,20 +58,21 @@ public function apply(Filter $filter, AbstractDb $collection): bool
5958
private function getAssetIdsByKeyword(string $value): array
6059
{
6160
$connection = $this->connection->getConnection();
61+
6262
return $connection->fetchAssoc(
6363
$connection->select()->from(
6464
$connection->select()
65-
->from(
66-
['asset_keywords_table' => $this->connection->getTableName(self::TABLE_ASSET_KEYWORD)],
67-
['id']
68-
)->where(
69-
'keyword = ?',
70-
$value
71-
)->joinInner(
72-
['keywords_table' => $this->connection->getTableName(self::TABLE_KEYWORDS)],
73-
'keywords_table.keyword_id = asset_keywords_table.id',
74-
['asset_id']
75-
),
65+
->from(
66+
['asset_keywords_table' => $this->connection->getTableName(self::TABLE_ASSET_KEYWORD)],
67+
['id']
68+
)->where(
69+
'keyword = ?',
70+
$value
71+
)->joinInner(
72+
['keywords_table' => $this->connection->getTableName(self::TABLE_KEYWORDS)],
73+
'keywords_table.keyword_id = asset_keywords_table.id',
74+
['asset_id']
75+
),
7676
['asset_id']
7777
)
7878
);

0 commit comments

Comments
 (0)