瀏覽代碼

[Tree] MaterializedPath: Some minor optimizations

comfortablynumb 13 年之前
父節點
當前提交
6352a95daa

+ 2 - 1
lib/Gedmo/Tree/Strategy.php

@@ -47,9 +47,10 @@ interface Strategy
      *
      * @param object $om - object manager
      * @param object $object - node
+     * @param object $ea - event adapter
      * @return void
      */
-    function processScheduledInsertion($om, $object);
+    function processScheduledInsertion($om, $object, $ea);
 
     /**
      * Operations on tree node updates

+ 20 - 2
lib/Gedmo/Tree/Strategy/AbstractMaterializedPath.php

@@ -52,6 +52,21 @@ abstract class AbstractMaterializedPath implements Strategy
         return Strategy::MATERIALIZED_PATH;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function processScheduledInsertion($om, $node, $ea)
+    {
+        $meta = $om->getClassMetadata(get_class($node));
+        $config = $this->listener->getConfiguration($om, $meta->name);
+
+        if ($meta->isIdentifier($config['path_source'])) {
+            $this->scheduledForPathProcess[spl_object_hash($node)] = node;
+        } else {
+            $this->updateNode($om, $node, $ea);
+        }
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -81,7 +96,11 @@ abstract class AbstractMaterializedPath implements Strategy
      */
     public function processPostPersist($om, $node, $ea)
     {
-        $this->updateNode($om, $node, $ea);
+        foreach ($this->scheduledForPathProcess as $node) {
+            $this->updateNode($om, $node, $ea);
+
+            unset($this->scheduledForPathProcess[spl_object_hash($node)]);
+        }
     }
 
     /**
@@ -89,7 +108,6 @@ abstract class AbstractMaterializedPath implements Strategy
      */
     public function onFlushEnd($om)
     {
-        $this->alreadyProcessedObjects = array();
         $this->scheduledForPathProcess = array();
     }
 

+ 0 - 8
lib/Gedmo/Tree/Strategy/ODM/MongoDB/MaterializedPath.php

@@ -16,14 +16,6 @@ use Gedmo\Tree\Strategy\AbstractMaterializedPath;
  */
 class MaterializedPath extends AbstractMaterializedPath
 {
-    /**
-     * {@inheritdoc}
-     */
-    public function processScheduledInsertion($om, $node)
-    {
-        // TODO
-    }
-
     /**
      * Remove node and its children
      *

+ 1 - 1
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -165,7 +165,7 @@ class Closure implements Strategy
      /**
      * {@inheritdoc}
      */
-    public function processScheduledInsertion($em, $node)
+    public function processScheduledInsertion($em, $node, $ea)
     {}
 
     /**

+ 1 - 1
lib/Gedmo/Tree/Strategy/ORM/Nested.php

@@ -128,7 +128,7 @@ class Nested implements Strategy
     /**
      * {@inheritdoc}
      */
-    public function processScheduledInsertion($em, $node)
+    public function processScheduledInsertion($em, $node, $ea)
     {
         $meta = $em->getClassMetadata(get_class($node));
         $config = $this->listener->getConfiguration($em, $meta->name);

+ 1 - 1
lib/Gedmo/Tree/TreeListener.php

@@ -108,7 +108,7 @@ class TreeListener extends MappedEventSubscriber
             $meta = $om->getClassMetadata(get_class($object));
             if ($config = $this->getConfiguration($om, $meta->name)) {
                 $usedClasses[$meta->name] = null;
-                $this->getStrategy($om, $meta->name)->processScheduledInsertion($om, $object);
+                $this->getStrategy($om, $meta->name)->processScheduledInsertion($om, $object, $ea);
                 $ea->recomputeSingleObjectChangeSet($uow, $meta, $object);
             }
         }