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