Skip to content

Commit b25499d

Browse files
committed
bug #48097 Fix search scope when performing fallback mapping driver detection (spideyfusion)
This PR was merged into the 5.4 branch. Discussion ---------- Fix search scope when performing fallback mapping driver detection | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a When using `auto_mapping` inside `orm` configuration to enable automatic entity registration for all bundles that are used within your application, the fallback mechanism for determining which mapping driver should be used for extracting entity information has a wrong starting point. Instead of beginning its search from the `Entity` folder, the entire bundle root gets traversed recursively, which can lead to wrong mapping driver being selected or just plainly having a performance hit during development just because the potential list of files that need to be examined can get huge. We actually stumbled upon this bug because we noticed a big jump in memory usage during development (`850+ MB vs ~100 MB`) ever since we switched to using attributes for describing our entities. Turns out, the `DoctrineBridge` was scanning all files inside our `Resources` folder (and we had **a lot** of files in there). Commits ------- c305722 Fix search scope when performing fallback mapping driver detection
2 parents 67e0e87 + c305722 commit b25499d

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ protected function detectMetadataDriver(string $dir, ContainerBuilder $container
279279
}
280280
$container->fileExists($resource, false);
281281

282-
if ($container->fileExists($dir.'/'.$this->getMappingObjectDefaultName(), false)) {
283-
return $this->detectMappingType($dir, $container);
282+
if ($container->fileExists($discoveryPath = $dir.'/'.$this->getMappingObjectDefaultName(), false)) {
283+
return $this->detectMappingType($discoveryPath, $container);
284284
}
285285

286286
return null;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\AttributesBundle\AnnotatedEntity;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
18+
/**
19+
* @Entity
20+
*/
21+
class Person
22+
{
23+
/** @Id @Column(type="integer") */
24+
protected $id;
25+
26+
/** @Column(type="string") */
27+
public $name;
28+
29+
public function __construct($id, $name)
30+
{
31+
$this->id = $id;
32+
$this->name = $name;
33+
}
34+
35+
public function __toString(): string
36+
{
37+
return (string) $this->name;
38+
}
39+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy