Skip to content

Commit

Permalink
DDC-1210 - Optimize UnitOfWork collection handling internally.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Oct 15, 2011
1 parent 7c244ab commit 4474d30
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/Doctrine/ORM/UnitOfWork.php
Expand Up @@ -490,8 +490,9 @@ public function computeChangeSet(ClassMetadata $class, $entity)
}
} else if ($orgValue instanceof PersistentCollection && $orgValue !== $actualValue) {
// A PersistentCollection was de-referenced, so delete it.
if ( ! in_array($orgValue, $this->collectionDeletions, true)) {
$this->collectionDeletions[] = $orgValue;
$coid = spl_object_hash($orgValue);
if ( ! isset($this->collectionDeletions[$coid]) ) {
$this->collectionDeletions[$coid] = $orgValue;
$changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored.
}
}
Expand Down Expand Up @@ -569,10 +570,11 @@ public function computeChangeSets()
private function computeAssociationChanges($assoc, $value)
{
if ($value instanceof PersistentCollection && $value->isDirty()) {
$coid = spl_object_hash($value);
if ($assoc['isOwningSide']) {
$this->collectionUpdates[] = $value;
$this->collectionUpdates[$coid] = $value;
}
$this->visitedCollections[] = $value;
$this->visitedCollections[$coid] = $value;
}

// Look through the entities, and in any of their associations, for transient (new)
Expand Down Expand Up @@ -1889,12 +1891,12 @@ public function scheduleCollectionDeletion(PersistentCollection $coll)
{
//TODO: if $coll is already scheduled for recreation ... what to do?
// Just remove $coll from the scheduled recreations?
$this->collectionDeletions[] = $coll;
$this->collectionDeletions[spl_object_hash($coll)] = $coll;
}

public function isCollectionScheduledForDeletion(PersistentCollection $coll)
{
return in_array($coll, $this->collectionsDeletions, true);
return isset( $this->collectionsDeletions[spl_object_hash($coll)] );
}

/**
Expand Down

0 comments on commit 4474d30

Please sign in to comment.