Skip to content

Commit 868be12

Browse files
authored
Merge pull request #6720 from pmattmann/feature/category-endpoint-performance
Disable FilterEagerLoadingsExtension for better performance
2 parents d0b10bc + 250bfa3 commit 868be12

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

api/config/services.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ services:
5353
tags:
5454
- 'app.input_filter'
5555

56+
App\Doctrine\Orm\Extension\FilterEagerLoadingsExtension:
57+
decorates: 'api_platform.doctrine.orm.query_extension.filter_eager_loading'
58+
5659
App\Serializer\Normalizer\RelatedCollectionLinkNormalizer:
5760
decorates: 'api_platform.hal.normalizer.item'
5861
arguments:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Doctrine\Orm\Extension;
4+
5+
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
6+
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
7+
use ApiPlatform\Metadata\Operation;
8+
use Doctrine\ORM\QueryBuilder;
9+
10+
final class FilterEagerLoadingsExtension implements QueryCollectionExtensionInterface {
11+
// @phpstan-ignore property.onlyWritten
12+
public function __construct(private QueryCollectionExtensionInterface $decorated) {}
13+
14+
public function applyToCollection(
15+
QueryBuilder $queryBuilder,
16+
QueryNameGeneratorInterface $queryNameGenerator,
17+
?string $resourceClass = null,
18+
?Operation $operation = null,
19+
array $context = []
20+
): void {
21+
// Manipulates $queryBuilder
22+
23+
// Orig:
24+
// select
25+
// from category c0_
26+
// inner join camp c1_ ON c0_.campId = c1_.id
27+
// ...
28+
// where c1_.id = ?
29+
30+
// New:
31+
// select ...
32+
// from category c0_
33+
// inner join camp c1_ ON c0_.campId = c1_.id
34+
// ...
35+
// where c0_.id IN (
36+
// SELECT c9_.id
37+
// FROM category c9_
38+
// INNER JOIN camp c10_ ON c9_.campId = c10_.id
39+
// WHERE c10_.id = ?
40+
// )
41+
42+
// Not clear, why ApiPlatform is doing this.
43+
// Orig-Verison performs better.
44+
// FilterEagerLoadingExtension is disabled.
45+
46+
// $this->decorated->applyToCollection($queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
47+
}
48+
}

0 commit comments

Comments
 (0)