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

Performance improvements #1093

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
51 changes: 42 additions & 9 deletions src/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function getQuery()
// Prepare mapping for joined tables
$filterToTableMapping = $this->getFieldMapping();

// visibility filter is added only to the outer query
if ($this->getInitialPopulation() !== null) {
$this->addFilter('visibility', ['both', 'catalog']);
}

// Process and generate all fields for the SQL query below
$orderField = $this->computeOrderByField($filterToTableMapping);
$selectFields = $this->computeSelectFields($filterToTableMapping);
Expand Down Expand Up @@ -324,6 +329,41 @@ protected function getFieldMapping()
)',
'joinType' => self::LEFT_JOIN,
],
'id_manufacturer' => [
'tableName' => 'product',
'tableAlias' => 'mid',
'fieldName' => 'id_manufacturer',
'joinCondition' => '(p.id_product = mid.id_product)',
'joinType' => self::INNER_JOIN,
],
'on_sale' => [
'tableName' => 'product',
'tableAlias' => 'ons',
'fieldName' => 'on_sale',
'joinCondition' => '(p.id_product = ons.id_product)',
'joinType' => self::INNER_JOIN,
],
'date_add' => [
'tableName' => 'product',
'tableAlias' => 'dadd',
'fieldName' => 'date_add',
'joinCondition' => '(p.id_product = dadd.id_product)',
'joinType' => self::INNER_JOIN,
],
'condition' => [
'tableName' => 'product',
'tableAlias' => 'pc',
'fieldName' => 'condition',
'joinCondition' => '(p.id_product = pc.id_product)',
'joinType' => self::INNER_JOIN,
],
'price' => [
'tableName' => 'product',
'tableAlias' => 'prc',
'fieldName' => 'price',
'joinCondition' => '(p.id_product = prc.id_product)',
'joinType' => self::INNER_JOIN,
],
];

return $filterToTableMapping;
Expand Down Expand Up @@ -652,7 +692,8 @@ protected function computeJoinConditions(array $filterToTableMapping)

$this->addJoinList($joinList, $this->getGroupFields()->getKeys(), $filterToTableMapping);

if (array_key_exists($this->getOrderField(), $filterToTableMapping)) {
// position field is part of the base query, no need to rejoin category_product
if (array_key_exists($this->getOrderField(), $filterToTableMapping) && $this->getOrderField() != 'position') {
$joinMapping = $filterToTableMapping[$this->getOrderField()];
$this->addJoinConditions($joinList, $joinMapping, $filterToTableMapping);
}
Expand Down Expand Up @@ -790,14 +831,6 @@ public function useFiltersAsInitialPopulation()
$this->setSelectFields(
[
'id_product',
'id_manufacturer',
'quantity',
'condition',
'weight',
'price',
'sales',
'on_sale',
'date_add',
]
);

Expand Down
9 changes: 4 additions & 5 deletions src/Product/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,10 @@ private function addSearchFilters($selectedFilters)
*/
private function addCommonFilters()
{
// Setting proper shop
$this->getSearchAdapter()->addFilter('id_shop', [(int) $this->context->shop->id]);

// Visibility of a product must be in catalog or both (search & catalog)
$this->addFilter('visibility', ['both', 'catalog']);
// Setting proper shop if multishop is enabled
if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) {
$this->getSearchAdapter()->addFilter('id_shop', [(int) $this->context->shop->id]);
}

// User must belong to one of the groups that can access the product
// (Actually it's categories that define access to a product, user must have access to at least
Expand Down