Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b99838

Browse files
committed
Compute commit order (inserts/deletes) on the entity level
1 parent 7a17d80 commit 3b99838

5 files changed

Lines changed: 112 additions & 152 deletions

File tree

lib/Doctrine/ORM/Internal/CommitOrder/Edge.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88
final class Edge
99
{
1010
/**
11-
* @var string
11+
* @var int
1212
* @readonly
1313
*/
1414
public $from;
1515

1616
/**
17-
* @var string
17+
* @var int
1818
* @readonly
1919
*/
2020
public $to;
2121

2222
/**
23-
* @var int
23+
* @var bool
2424
* @readonly
2525
*/
26-
public $weight;
26+
public $optional;
2727

28-
public function __construct(string $from, string $to, int $weight)
28+
public function __construct(int $from, int $to, bool $optional)
2929
{
30-
$this->from = $from;
31-
$this->to = $to;
32-
$this->weight = $weight;
30+
$this->from = $from;
31+
$this->to = $to;
32+
$this->optional = $optional;
3333
}
3434
}

lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
namespace Doctrine\ORM\Internal\CommitOrder;
66

7-
use Doctrine\ORM\Mapping\ClassMetadata;
8-
97
/** @internal */
108
final class Vertex
119
{
1210
/**
13-
* @var string
11+
* @var int
1412
* @readonly
1513
*/
1614
public $hash;
@@ -22,15 +20,16 @@ final class Vertex
2220
public $state = VertexState::NOT_VISITED;
2321

2422
/**
25-
* @var ClassMetadata
23+
* @var object
2624
* @readonly
2725
*/
2826
public $value;
2927

3028
/** @var array<string, Edge> */
3129
public $dependencyList = [];
3230

33-
public function __construct(string $hash, ClassMetadata $value)
31+
/** @param object $value */
32+
public function __construct(int $hash, $value)
3433
{
3534
$this->hash = $hash;
3635
$this->value = $value;

lib/Doctrine/ORM/Internal/CommitOrderCalculator.php

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Doctrine\ORM\Internal\CommitOrder\Edge;
88
use Doctrine\ORM\Internal\CommitOrder\Vertex;
99
use Doctrine\ORM\Internal\CommitOrder\VertexState;
10-
use Doctrine\ORM\Mapping\ClassMetadata;
1110

1211
use function array_reverse;
1312

@@ -34,55 +33,42 @@ class CommitOrderCalculator
3433
*
3534
* Keys are provided hashes and values are the node definition objects.
3635
*
37-
* @var array<string, Vertex>
36+
* @var array<int, Vertex>
3837
*/
3938
private $nodeList = [];
4039

4140
/**
4241
* Volatile variable holding calculated nodes during sorting process.
4342
*
44-
* @psalm-var list<ClassMetadata>
43+
* @psalm-var array<int, object>
4544
*/
4645
private $sortedNodeList = [];
4746

4847
/**
4948
* Checks for node (vertex) existence in graph.
50-
*
51-
* @param string $hash
52-
*
53-
* @return bool
5449
*/
55-
public function hasNode($hash)
50+
public function hasNode(int $hash): book
5651
{
5752
return isset($this->nodeList[$hash]);
5853
}
5954

6055
/**
6156
* Adds a new node (vertex) to the graph, assigning its hash and value.
6257
*
63-
* @param string $hash
64-
* @param ClassMetadata $node
65-
*
66-
* @return void
58+
* @param object $node
6759
*/
68-
public function addNode($hash, $node)
60+
public function addNode(int $hash, $node): void
6961
{
7062
$this->nodeList[$hash] = new Vertex($hash, $node);
7163
}
7264

7365
/**
7466
* Adds a new dependency (edge) to the graph using their hashes.
75-
*
76-
* @param string $fromHash
77-
* @param string $toHash
78-
* @param int $weight
79-
*
80-
* @return void
8167
*/
82-
public function addDependency($fromHash, $toHash, $weight)
68+
public function addDependency(int $fromHash, int $toHash, bool $optional): void
8369
{
8470
$this->nodeList[$fromHash]->dependencyList[$toHash]
85-
= new Edge($fromHash, $toHash, $weight);
71+
= new Edge($fromHash, $toHash, $optional);
8672
}
8773

8874
/**
@@ -91,7 +77,7 @@ public function addDependency($fromHash, $toHash, $weight)
9177
*
9278
* {@internal Highly performance-sensitive method.}
9379
*
94-
* @psalm-return list<ClassMetadata>
80+
* @psalm-return list<object>
9581
*/
9682
public function sort()
9783
{
@@ -108,7 +94,7 @@ public function sort()
10894
$this->nodeList = [];
10995
$this->sortedNodeList = [];
11096

111-
return array_reverse($sortedList);
97+
return array_reverse($sortedList, true);
11298
}
11399

114100
/**
@@ -131,7 +117,7 @@ private function visit(Vertex $vertex): void
131117
case VertexState::IN_PROGRESS:
132118
if (
133119
isset($adjacentVertex->dependencyList[$vertex->hash]) &&
134-
$adjacentVertex->dependencyList[$vertex->hash]->weight < $edge->weight
120+
$adjacentVertex->dependencyList[$vertex->hash]->optional < $edge->optional
135121
) {
136122
// If we have some non-visited dependencies in the in-progress dependency, we
137123
// need to visit them before adding the node.
@@ -145,7 +131,7 @@ private function visit(Vertex $vertex): void
145131

146132
$adjacentVertex->state = VertexState::VISITED;
147133

148-
$this->sortedNodeList[] = $adjacentVertex->value;
134+
$this->sortedNodeList[$adjacentVertex->hash] = $adjacentVertex->value;
149135
}
150136

151137
break;
@@ -158,7 +144,7 @@ private function visit(Vertex $vertex): void
158144
if ($vertex->state !== VertexState::VISITED) {
159145
$vertex->state = VertexState::VISITED;
160146

161-
$this->sortedNodeList[] = $vertex->value;
147+
$this->sortedNodeList[$vertex->hash] = $vertex->value;
162148
}
163149
}
164150
}

0 commit comments

Comments
 (0)