1

我有一个包含 9 种类型的节点、9 种关系类型和 50 个条目(节点和关系)的数据库,当我尝试保存一个新节点时,库在函数中执行 140 次查询。

我的 PHP 代码:

$iUser = new User();
$iUser->setEmail($mail);
$iUser->setName($name);
$this->getEntityManager()->persist($iUser); // <-- It's do 140 queries
$this->getEntityManager()->flush();

类定义

/** @OGM\Node(label="User") */
class User {
    @OGM\GraphId()
    private $id;
    /** @OGM\Property(type="string") */
    private $name;
    /** @OGM\Property(type="string") */
    private $mail;

    // Set, genters, ...
}

库版本:

graphaware/neo4j-bolt                1.10.0
graphaware/neo4j-common              3.5.0
graphaware/neo4j-php-client          4.8.1
graphaware/neo4j-php-ogm             1.0.0-RC5

查询一直重复数据库中的关系和其他ID,相同的查询更改名称关系或ID,查询是:

查询

MATCH (n) WHERE id(n) = {id} RETURN size((n)<-[:`<name relation>`]-()) AS users     

Parameter: array:1 [▼
  "id" => 189
]

MATCH (n) WHERE id(n) = {id} MATCH (n)<-[vendor_neo4j_entity_roleentity_users:`HAVE_ROL_GLOBAL`]-(vendor_neo4j_entity_haverolglobalrelationship) RETURN {target: startNode(vendor_neo4j_entity_roleentity_users), re: vendor_neo4j_entity_roleentity_users} AS vendor_neo4j_entity_roleentity_users 

Parameter: array:1 [▼
  "id" => 189
]

代码的第一次查询跟踪

0 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\Persisters\BasicEntityPersister.php"
      "line" => 131
      "function" => "run"
      "class" => "GraphAware\Neo4j\Client\Client"
    ]
    1 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\Proxy\RelationshipEntityCollectionInitializer.php"
      "line" => 29
      "function" => "getCountForRelationship"
      "class" => "GraphAware\Neo4j\OGM\Persisters\BasicEntityPersister"
    ]
    2 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\Proxy\LazyCollection.php"
      "line" => 87
      "function" => "getCount"
      "class" => "GraphAware\Neo4j\OGM\Proxy\RelationshipEntityCollectionInitializer"
    ]
    3 => array:4 [▼
      "file" => ""
      "line" => 0
      "function" => "count"
      "class" => "GraphAware\Neo4j\OGM\Proxy\LazyCollection"
    ]
    4 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
      "line" => 493
      "function" => "count"
      "class" => ""
    ]
    5 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
      "line" => 150
      "function" => "traverseRelationshipEntities"
      "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
    ]
    6 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
      "line" => 501
      "function" => "doPersist"
      "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
    ]
    7 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
      "line" => 150
      "function" => "traverseRelationshipEntities"
      "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
    ]
    8 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
      "line" => 123
      "function" => "doPersist"
      "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
    ]
    9 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\EntityManager.php"
      "line" => 223
      "function" => "persist"
      "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
    ]
    10 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\src\vendor\Neo4j\Repository\UserRepository.php"
      "line" => 184
      "function" => "persist"
      "class" => "GraphAware\Neo4j\OGM\EntityManager"
    ]
    11 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\src\vendor\CoreBundle\Controller\UsersController.php"
      "line" => 214
      "function" => "editUser"
      "class" => "vendor\Neo4j\Repository\UserRepository"
    ]
    12 => array:4 [▼
      "file" => ""
      "line" => 0
      "function" => "saveUserAction"
      "class" => "vendor\CoreBundle\Controller\UsersController"
    ]
    13 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php"
      "line" => 153
      "function" => "call_user_func_array"
      "class" => ""
    ]
    14 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php"
      "line" => 68
      "function" => "handleRaw"
      "class" => "Symfony\Component\HttpKernel\HttpKernel"
    ]
    15 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php"
      "line" => 171
      "function" => "handle"
      "class" => "Symfony\Component\HttpKernel\HttpKernel"
    ]
    16 => array:4 [▼
      "file" => "C:\wamp64\www\vCheck\web\app.php"
      "line" => 20
      "function" => "handle"
      "class" => "Symfony\Component\HttpKernel\Kernel"

第二个查询跟踪

0 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\Persisters\BasicEntityPersister.php"
  "line" => 122
  "function" => "run"
  "class" => "GraphAware\Neo4j\Client\Client"
]
1 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\Proxy\RelationshipEntityCollectionInitializer.php"
  "line" => 22
  "function" => "getRelationshipEntityCollection"
  "class" => "GraphAware\Neo4j\OGM\Persisters\BasicEntityPersister"
]
2 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\Proxy\LazyCollection.php"
  "line" => 52
  "function" => "initialize"
  "class" => "GraphAware\Neo4j\OGM\Proxy\RelationshipEntityCollectionInitializer"
]
3 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\doctrine\collections\lib\Doctrine\Common\Collections\AbstractLazyCollection.php"
  "line" => 332
  "function" => "doInitialize"
  "class" => "GraphAware\Neo4j\OGM\Proxy\LazyCollection"
]
4 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\doctrine\collections\lib\Doctrine\Common\Collections\AbstractLazyCollection.php"
  "line" => 274
  "function" => "initialize"
  "class" => "Doctrine\Common\Collections\AbstractLazyCollection"
]
5 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
  "line" => 497
  "function" => "getIterator"
  "class" => "Doctrine\Common\Collections\AbstractLazyCollection"
]
6 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
  "line" => 150
  "function" => "traverseRelationshipEntities"
  "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
]
7 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
  "line" => 501
  "function" => "doPersist"
  "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
]
8 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
  "line" => 150
  "function" => "traverseRelationshipEntities"
  "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
]
9 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\UnitOfWork.php"
  "line" => 123
  "function" => "doPersist"
  "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
]
10 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\graphaware\neo4j-php-ogm\src\EntityManager.php"
  "line" => 223
  "function" => "persist"
  "class" => "GraphAware\Neo4j\OGM\UnitOfWork"
]
11 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\src\vendor\Neo4j\Repository\UserRepository.php"
  "line" => 184
  "function" => "persist"
  "class" => "GraphAware\Neo4j\OGM\EntityManager"
]
12 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\src\vendor\CoreBundle\Controller\UsersController.php"
  "line" => 214
  "function" => "editUser"
  "class" => "vendor\Neo4j\Repository\UserRepository"
]
13 => array:4 [▼
  "file" => ""
  "line" => 0
  "function" => "saveUserAction"
  "class" => "vendor\CoreBundle\Controller\UsersController"
]
14 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php"
  "line" => 153
  "function" => "call_user_func_array"
  "class" => ""
]
15 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php"
  "line" => 68
  "function" => "handleRaw"
  "class" => "Symfony\Component\HttpKernel\HttpKernel"
]
16 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php"
  "line" => 171
  "function" => "handle"
  "class" => "Symfony\Component\HttpKernel\HttpKernel"
]
17 => array:4 [▼
  "file" => "C:\wamp64\www\vCheck\web\app.php"
  "line" => 20
  "function" => "handle"
  "class" => "Symfony\Component\HttpKernel\Kernel"
]

有人知道解决这个吗?

4

0 回答 0