Skip to content

Commit

Permalink
bug #48097 Fix search scope when performing fallback mapping driver d…
Browse files Browse the repository at this point in the history
…etection (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
  • Loading branch information
fabpot committed Nov 4, 2022
2 parents 67e0e87 + c305722 commit b25499d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Expand Up @@ -279,8 +279,8 @@ protected function detectMetadataDriver(string $dir, ContainerBuilder $container
}
$container->fileExists($resource, false);

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

return null;
Expand Down
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fixtures\Bundles\AttributesBundle\AnnotatedEntity;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;

/**
* @Entity
*/
class Person
{
/** @Id @Column(type="integer") */
protected $id;

/** @Column(type="string") */
public $name;

public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
}

public function __toString(): string
{
return (string) $this->name;
}
}

0 comments on commit b25499d

Please sign in to comment.