mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 22:36:02 +03:00
Perf: memoize collectSubfields
This commit is contained in:
parent
b705ee797f
commit
5c9b5576e6
@ -273,6 +273,11 @@ class Executor
|
|||||||
*/
|
*/
|
||||||
private $promises;
|
private $promises;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \SplObjectStorage
|
||||||
|
*/
|
||||||
|
private $subFieldCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executor constructor.
|
* Executor constructor.
|
||||||
*
|
*
|
||||||
@ -285,6 +290,7 @@ class Executor
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->exeContext = $context;
|
$this->exeContext = $context;
|
||||||
|
$this->subFieldCache = new \SplObjectStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1311,12 +1317,28 @@ class Executor
|
|||||||
&$result
|
&$result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Collect sub-fields to execute to complete this value.
|
$subFieldNodes = $this->collectSubFields($returnType, $fieldNodes);
|
||||||
$subFieldNodes = new \ArrayObject();
|
return $this->executeFields($returnType, $result, $path, $subFieldNodes);
|
||||||
$visitedFragmentNames = new \ArrayObject();
|
}
|
||||||
|
|
||||||
foreach ($fieldNodes as $fieldNode) {
|
/**
|
||||||
if (isset($fieldNode->selectionSet)) {
|
* @param ObjectType $returnType
|
||||||
|
* @param $fieldNodes
|
||||||
|
* @return \ArrayObject
|
||||||
|
*/
|
||||||
|
private function collectSubFields(ObjectType $returnType, $fieldNodes)
|
||||||
|
{
|
||||||
|
if (!isset($this->subFieldCache[$returnType])) {
|
||||||
|
$this->subFieldCache[$returnType] = new \SplObjectStorage();
|
||||||
|
}
|
||||||
|
if (!isset($this->subFieldCache[$returnType][$fieldNodes])) {
|
||||||
|
// Collect sub-fields to execute to complete this value.
|
||||||
|
$subFieldNodes = new \ArrayObject();
|
||||||
|
$visitedFragmentNames = new \ArrayObject();
|
||||||
|
foreach ($fieldNodes as $fieldNode) {
|
||||||
|
if (!isset($fieldNode->selectionSet)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$subFieldNodes = $this->collectFields(
|
$subFieldNodes = $this->collectFields(
|
||||||
$returnType,
|
$returnType,
|
||||||
$fieldNode->selectionSet,
|
$fieldNode->selectionSet,
|
||||||
@ -1324,9 +1346,9 @@ class Executor
|
|||||||
$visitedFragmentNames
|
$visitedFragmentNames
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
$this->subFieldCache[$returnType][$fieldNodes] = $subFieldNodes;
|
||||||
}
|
}
|
||||||
|
return $this->subFieldCache[$returnType][$fieldNodes];
|
||||||
return $this->executeFields($returnType, $result, $path, $subFieldNodes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user