Skip to content

Commit 7d61268

Browse files
committed
Reduced calls to $this->getvertexCollections() to a minimum.
1 parent 9b35428 commit 7d61268

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/triagens/ArangoDb/GraphHandler.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,21 +594,32 @@ public function saveVertex($graph, $document, $collection = null)
594594
if (is_array($document)) {
595595
$document = Vertex::createFromArray($document);
596596
}
597+
598+
$vertexCollections = $this->getVertexCollections($graph);
599+
$vertexCollectionsCount = count($vertexCollections);
597600
if ($collection === null) {
598-
if (count($this->getVertexCollections($graph)) !== 1) {
601+
if ($vertexCollectionsCount !== 1) {
599602
throw new ClientException('A collection must be provided.');
600603
}
601-
else if (count($this->getVertexCollections($graph)) === 1) {
602-
$collection = $this->getVertexCollections($graph);
603-
$collection = $collection[0];
604+
else if ($vertexCollectionsCount === 1) {
605+
$collection = $vertexCollections[0];
604606
}
605607
}
606608
$data = $document->getAll();
607609
$url = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_VERTEX, $collection]);
608610

609611
$response = $this->getConnection()->post($url, $this->json_encode_wrapper($data));
610612

611-
$jsonArray = $response->getJson();
613+
// This makes sure that if we're in batch mode, it will not go further and choke on the checks below.
614+
// Caution: Instead of a document ID, we are returning the batchpart object.
615+
// The Id of the BatchPart can be retrieved by calling getId() on it.
616+
// We're basically returning an object here, in order not to accidentally use the batch part id as the document id
617+
if ($batchPart = $response->getBatchPart())
618+
{
619+
return $batchPart;
620+
}
621+
622+
$jsonArray = $response->getJson();
612623
$vertex = $jsonArray['vertex'];
613624

614625
$document->setInternalId($vertex[Vertex::ENTRY_ID]);

0 commit comments

Comments
 (0)