Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Database/DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ final class DatabaseManager implements DatabaseProviderInterface, LoggerAwareInt
/** @var array<string, true> Drivers created from the config, closed with the manager. */
private array $ownDrivers = [];

/** @var list<string>|null names of the configured drivers (the configuration does not change) */
private ?array $driverNames = null;

private ?LoggerInterface $logger = null;

public function __construct(
Expand Down Expand Up @@ -136,6 +139,21 @@ public function getDrivers(): array
{
// Names only: building every configured driver here just to read its key made each call
// construct throwaway driver objects.
$configured = $this->driverNames ??= $this->config->getDriverNames();
if (\count($this->drivers) >= \count($configured)) {
// Every configured driver exists already (the usual case after the first request):
// the merge below would return exactly these, in this order.
$complete = true;
foreach ($configured as $name) {
if (!isset($this->drivers[$name])) {
$complete = false;
break;
}
}
if ($complete) {
return \array_values($this->drivers);
}
}
$names = \array_unique(
\array_merge(
\array_keys($this->drivers),
Expand Down
12 changes: 8 additions & 4 deletions src/ORM/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,10 @@ public function fetchOne(?array $query = null): ?object
{
if (!$this->customized && ($query === null || $query === [])) {
// Same entity as below through the cached statement and row maker of the shape.
$rows = (clone $this)->limit(1)->fetchShape();
// Once the shape with `limit(1)` has a plan, it runs without cloning this select.
$rows = isset($this->shapes[$this->shape . "limit\0" . "1\1"])
? $this->fetchShape("limit\0" . "1\1")
: (clone $this)->limit(1)->fetchShape();
if ($rows !== null) {
return $rows[0] ?? null;
}
Expand Down Expand Up @@ -1214,13 +1217,14 @@ private function applyRecorded(): void
*
* @return list<TEntity>|null
*/
private function fetchShape(): ?array
/** @param string $suffix recorded calls (no values) appended to this shape, already planned */
private function fetchShape(string $suffix = ''): ?array
{
if ($this->customized) {
return null;
}
$plan = $this->shapes[$this->shape] ?? null;
if ($plan === null && \count($this->shapes) < 1024) {
$plan = $this->shapes[$this->shape . $suffix] ?? null;
if ($plan === null && $suffix === '' && \count($this->shapes) < 1024) {
$plan = $this->shapes[$this->shape] = $this->shapePlan();
}
if (!$plan) {
Expand Down
Loading