forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next-34023/slow-query' into 'trunk'
NEXT-34023 - Slow query with criteria term See merge request shopware/6/product/platform!13146
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
changelog/_unreleased/2024-02-26-slow-query-with-criteria-term.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: Slow query with criteria term | ||
issue: NEXT-34023 | ||
author: oskroblin Skroblin | ||
author_email: [email protected] | ||
--- | ||
|
||
# Core | ||
* Removed `SearchRanking` from `product.categories` and `product.tags` association to improve search performance when providing a criteria term via API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Tests\Unit\Core\Content\Product; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use Shopware\Core\Content\Product\ProductDefinition; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\EntityWriteGateway; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SearchRanking; | ||
use Shopware\Core\Test\Stub\DataAbstractionLayer\StaticDefinitionInstanceRegistry; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[CoversClass(ProductDefinition::class)] | ||
class ProductDefinitionTest extends TestCase | ||
{ | ||
public function testSearchFields(): void | ||
{ | ||
// don't change this list, each additional field will reduce the performance | ||
|
||
$registry = new StaticDefinitionInstanceRegistry( | ||
[ProductDefinition::class], | ||
$this->createMock(ValidatorInterface::class), | ||
$this->createMock(EntityWriteGateway::class) | ||
); | ||
|
||
$definition = $registry->getByEntityName('product'); | ||
|
||
$fields = $definition->getFields(); | ||
|
||
$searchable = $fields->filterByFlag(SearchRanking::class); | ||
|
||
$keys = $searchable->getKeys(); | ||
|
||
// NEVER add an association to this list!!! otherwise, the API query takes too long and shops with many products (more than 1000) will fail | ||
$expected = ['customSearchKeywords', 'productNumber', 'manufacturerNumber', 'ean', 'name']; | ||
|
||
sort($expected); | ||
sort($keys); | ||
|
||
static::assertEquals($expected, $keys); | ||
} | ||
} |