Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

38934 slow processing attribute table source_model #39483

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,25 @@ public function getAllOptions($withEmpty = true, $defaultValues = false)
* @param bool $withEmpty Add empty option to array
* @return array
*/
public function getSpecificOptions($ids, $withEmpty = true)
public function getSpecificOptions($ids, $withEmpty = true)
{
$options = $this->_attrOptionCollectionFactory->create()
->setPositionOrder('asc')
->setAttributeFilter($this->getAttribute()->getId())
->addFieldToFilter('main_table.option_id', ['in' => $ids])
->setStoreFilter($this->getAttribute()->getStoreId())
->load()
->toOptionArray();
$allOptions = $this->getAllOptions(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is happened if attribute have 10k options?

$specificOptions = [];
if (is_string($ids) && strpos($ids, ',') !== false) {
$ids = explode(',', $ids);
}
if (!is_array($ids)) {
$ids = (array)$ids;
}
foreach ($allOptions as $option) {
if (isset($option['value']) && in_array($option['value'], $ids)) {
$specificOptions[] = $option;
}
}
if ($withEmpty) {
$options = $this->addEmptyOption($options);
$specificOptions = $this->addEmptyOption($specificOptions);
}
return $options;
return $specificOptions;
}

/**
Expand Down