Skip to content

Commit

Permalink
[WIP] improve performance for loading the standard node types
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed May 29, 2015
1 parent c1d311a commit 5c6691c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/Jackalope/Transport/DoctrineDBAL/CachedClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,36 @@ protected function fetchUserNodeTypes()
return $result;
}

/**
* {@inheritDoc}
*/
public function hasNodeType($nodeTypeName)
{
$cacheKey = 'hasnodetypes: '.serialize($nodeTypeName);
$result = $this->caches['meta']->fetch($cacheKey);
if (!$result) {
$result = parent::hasNodeType($nodeTypeName);
$this->caches['meta']->save($cacheKey, $result);
}

return $result;
}

/**
* {@inheritDoc}
*/
public function getSubTypes($nodeTypeName)
{
$cacheKey = 'nodesubtypes: '.serialize($nodeTypeName);
$result = $this->caches['meta']->fetch($cacheKey);
if (!$result) {
$result = parent::getSubTypes($nodeTypeName);
$this->caches['meta']->save($cacheKey, $result);
}

return $result;
}

/**
* {@inheritDoc}
*/
Expand Down
39 changes: 33 additions & 6 deletions src/Jackalope/Transport/DoctrineDBAL/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1977,18 +1977,45 @@ protected function getIdentifier($path, $properties)
return $this->generateUuid();
}

/**
* {@inheritDoc}
*/
public function hasNodeType($nodeType)
{
if (StandardNodeTypes::hasNodeType($nodeType)) {
return true;
}

$query = "SELECT 1 FROM phpcr_type_nodes WHERE name = ?";
$superTypes = $this->getConnection()->fetchColumn($query, array($nodeType));
return (bool) $superTypes;
}

/**
* {@inheritDoc}
*/
public function getSubTypes($nodeType)
{
if (StandardNodeTypes::hasNodeType($nodeType)) {
return StandardNodeTypes::getSubTypes($nodeType);
}

$query = "SELECT supertypes FROM phpcr_type_nodes WHERE name = ?";
$superTypes = $this->getConnection()->fetchColumn($query, array($nodeType));
return array_filter(explode(' ', $superTypes));
}

/**
* {@inheritDoc}
*/
public function getNodeTypes($nodeTypes = array())
{
$standardTypes = StandardNodeTypes::getNodeTypeData();
$standardTypes = StandardNodeTypes::getNodeTypeData($nodeTypes);

$userTypes = $this->fetchUserNodeTypes();
$userTypes = array_diff($nodeTypes, array_keys($standardTypes));

if ($nodeTypes) {
$nodeTypes = array_flip($nodeTypes);
return array_values(array_intersect_key($standardTypes, $nodeTypes) + array_intersect_key($userTypes, $nodeTypes));
if (!empty($userTypes)) {
$userTypes = $this->fetchUserNodeTypes($userTypes);
}

return array_values($standardTypes + $userTypes);
Expand All @@ -2001,7 +2028,7 @@ public function getNodeTypes($nodeTypes = array())
*
* @return array
*/
protected function fetchUserNodeTypes()
protected function fetchUserNodeTypes($nodeTypes)
{
$result = array();
$query = "SELECT * FROM phpcr_type_nodes";
Expand Down

0 comments on commit 5c6691c

Please sign in to comment.