-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disable FilterEagerLoadingsExtension for better performance
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
api/src/Doctrine/Orm/Extension/FilterEagerLoadingsExtension.php
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,47 @@ | ||
<?php | ||
|
||
namespace App\Doctrine\Orm\Extension; | ||
|
||
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; | ||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use Doctrine\ORM\QueryBuilder; | ||
|
||
final class FilterEagerLoadingsExtension implements QueryCollectionExtensionInterface { | ||
public function __construct(private QueryCollectionExtensionInterface $decorated) {} | ||
|
||
public function applyToCollection( | ||
QueryBuilder $queryBuilder, | ||
QueryNameGeneratorInterface $queryNameGenerator, | ||
?string $resourceClass = null, | ||
?Operation $operation = null, | ||
array $context = [] | ||
): void { | ||
// Manipulates $queryBuilder | ||
|
||
// Orig: | ||
// select | ||
// from category c0_ | ||
// inner join camp c1_ ON c0_.campId = c1_.id | ||
// ... | ||
// where c1_.id = ? | ||
// New: | ||
// select ... | ||
// from category c0_ | ||
// inner join camp c1_ ON c0_.campId = c1_.id | ||
// ... | ||
// where c0_.id IN ( | ||
// SELECT c9_.id | ||
// FROM category c9_ | ||
// INNER JOIN camp c10_ ON c9_.campId = c10_.id | ||
// WHERE c10_.id = ? | ||
// ) | ||
|
||
// Not clear, why ApiPlatform is doing this. | ||
// Orig-Verison performs better. | ||
// FilterEagerLoadingExtension is disabled. | ||
|
||
$this->decorated->applyToCollection($queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context); | ||
} | ||
} |