Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Compute a changeset only once and reset after commit #130

Merged
merged 3 commits into from

2 participants

@uwej711

Through the cascading of the changeset calculation (parent and child annotations) a changeset has been computed more than once in a single commit/flush.

@uwej711 uwej711 Compute a changeset only once and reset after commit
Through the cascading of the changeset calculation (parent and child annotations) a changeset has been computed more than once in a single commit/flush.
f6c0f1a
lib/Doctrine/ODM/PHPCR/UnitOfWork.php
@@ -1232,6 +1237,16 @@ public function commit($document = null)
$this->scheduledMoves =
$this->scheduledInserts =
$this->visitedCollections = array();
+
+ if (null === $document) {
+ $this->documentChangesets = array();
@lsmith77 Owner

can't we just always reset this to an empty array?

@uwej711
uwej711 added a note

Yes, I was too cautious ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ODM/PHPCR/UnitOfWork.php
((5 lines not shown))
$oid = spl_object_hash($document);
+
+ if (isset($this->documentChangesets[$oid])) {
@lsmith77 Owner

but what if the parent was previously persisted and there were no changes, we would continue to attempt to compute a change set. imho we should have a separate array to track for which objects we have attempted to compute a change set in this flush() call

@uwej711
uwej711 added a note

This simply fixes the wrong calculation of the changesets and yes, it would be calculated again, if there where no changes (which is still better than it was before). Having the other array would work the same way, set in computeChangeSet, reset in commit and the other places ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77 lsmith77 merged commit aea067f into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2012
  1. @uwej711

    Compute a changeset only once and reset after commit

    uwej711 authored
    Through the cascading of the changeset calculation (parent and child annotations) a changeset has been computed more than once in a single commit/flush.
  2. @uwej711

    Always reset all changesets

    uwej711 authored
  3. @uwej711
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 2 deletions.
  1. +19 −2 lib/Doctrine/ODM/PHPCR/UnitOfWork.php
View
21 lib/Doctrine/ODM/PHPCR/UnitOfWork.php
@@ -156,6 +156,11 @@ class UnitOfWork
/**
* @var array
*/
+ private $changesetComputed = array();
+
+ /**
+ * @var array
+ */
private $idGenerators = array();
/**
@@ -818,8 +823,15 @@ private function computeChangeSet(ClassMetadata $class, $document)
return;
}
- $actualData = $this->getDocumentActualData($class, $document);
$oid = spl_object_hash($document);
+
+ if (in_array($oid, $this->changesetComputed)) {
+ return;
+ }
+
+ $this->changesetComputed[] = $oid;
+
+ $actualData = $this->getDocumentActualData($class, $document);
$id = $this->getDocumentId($document);
$isNew = !isset($this->originalData[$oid]);
@@ -1231,7 +1243,9 @@ public function commit($document = null)
$this->scheduledRemovals =
$this->scheduledMoves =
$this->scheduledInserts =
- $this->visitedCollections = array();
+ $this->visitedCollections =
+ $this->documentChangesets =
+ $this->changesetComputed = array();
}
/**
@@ -1734,6 +1748,8 @@ private function unregisterDocument($document)
$this->documentHistory[$oid],
$this->documentVersion[$oid]
);
+
+ $this->changesetComputed = array_diff($this->changesetComputed, array($oid));
}
/**
@@ -1891,6 +1907,7 @@ public function clear()
$this->nonMappedData =
$this->originalData =
$this->documentChangesets =
+ $this->changesetComputed =
$this->scheduledUpdates =
$this->scheduledAssociationUpdates =
$this->scheduledInserts =
Something went wrong with that request. Please try again.