Skip to content
This repository
Browse code

Merge pull request #130 from uwej711/fix_compute_changeset

Compute a changeset only once and reset after commit
  • Loading branch information...
commit aea067fd3e18814b8f0f1dfb09908cc30208a8d1 2 parents 791a663 + 1b45833
Lukas Kahwe Smith authored April 11, 2012

Showing 1 changed file with 19 additions and 2 deletions. Show diff stats Hide diff stats

  1. 21  lib/Doctrine/ODM/PHPCR/UnitOfWork.php
21  lib/Doctrine/ODM/PHPCR/UnitOfWork.php
@@ -156,6 +156,11 @@ class UnitOfWork
156 156
     /**
157 157
      * @var array
158 158
      */
  159
+    private $changesetComputed = array();
  160
+     
  161
+    /**
  162
+     * @var array
  163
+     */
159 164
     private $idGenerators = array();
160 165
 
161 166
     /**
@@ -818,8 +823,15 @@ private function computeChangeSet(ClassMetadata $class, $document)
818 823
             return;
819 824
         }
820 825
 
821  
-        $actualData = $this->getDocumentActualData($class, $document);
822 826
         $oid = spl_object_hash($document);
  827
+
  828
+        if (in_array($oid, $this->changesetComputed)) {
  829
+            return;
  830
+        }
  831
+
  832
+        $this->changesetComputed[] = $oid;
  833
+
  834
+        $actualData = $this->getDocumentActualData($class, $document);
823 835
         $id = $this->getDocumentId($document);
824 836
 
825 837
         $isNew = !isset($this->originalData[$oid]);
@@ -1231,7 +1243,9 @@ public function commit($document = null)
1231 1243
         $this->scheduledRemovals =
1232 1244
         $this->scheduledMoves =
1233 1245
         $this->scheduledInserts =
1234  
-        $this->visitedCollections = array();
  1246
+        $this->visitedCollections =
  1247
+        $this->documentChangesets =
  1248
+        $this->changesetComputed = array();
1235 1249
     }
1236 1250
 
1237 1251
     /**
@@ -1734,6 +1748,8 @@ private function unregisterDocument($document)
1734 1748
             $this->documentHistory[$oid],
1735 1749
             $this->documentVersion[$oid]
1736 1750
         );
  1751
+
  1752
+        $this->changesetComputed = array_diff($this->changesetComputed, array($oid));
1737 1753
     }
1738 1754
 
1739 1755
     /**
@@ -1891,6 +1907,7 @@ public function clear()
1891 1907
         $this->nonMappedData =
1892 1908
         $this->originalData =
1893 1909
         $this->documentChangesets =
  1910
+        $this->changesetComputed =
1894 1911
         $this->scheduledUpdates =
1895 1912
         $this->scheduledAssociationUpdates =
1896 1913
         $this->scheduledInserts =

0 notes on commit aea067f

Please sign in to comment.
Something went wrong with that request. Please try again.