Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add an optional caching mechanism to the full XML tree
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Dec 3, 2013
1 parent 99449b6 commit 9cd5c10
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
61 changes: 58 additions & 3 deletions core/src/plugins/meta.filehasher/class.FileHasher.php
Expand Up @@ -47,7 +47,15 @@ public function parseSpecificContributions(&$contribNode)
// REMOVE rsync actions, this will advertise the fact that
// rsync is not enabled.
$xp = new DOMXPath($contribNode->ownerDocument);
$children = $xp->query("action", $contribNode);
$children = $xp->query("action[contains(@name, 'filehasher')]", $contribNode);
foreach ($children as $child) {
$contribNode->removeChild($child);
}
}
if (!$this->getFilteredOption("CACHE_XML_TREE") && $contribNode->nodeName == "actions") {
// REMOVE pre and post process on LS action
$xp = new DOMXPath($contribNode->ownerDocument);
$children = $xp->query("action[@name='ls']", $contribNode);
foreach ($children as $child) {
$contribNode->removeChild($child);
}
Expand All @@ -65,6 +73,44 @@ public function initMeta($accessDriver)
$this->metaStore->initMeta($accessDriver);
}

private function getTreeName()
{
$base = AJXP_SHARED_CACHE_DIR."/trees/tree-".ConfService::getRepository()->getId();
$secuScope = ConfService::getRepository()->securityScope();
if ($secuScope == "USER") {
$base .= "-".AuthService::getLoggedUser()->getId();
} else if ($secuScope == "GROUP") {
$base .= "-".str_replace("/", "_", AuthService::getLoggedUser()->getGroupPath());
}
return $base . "-full.xml";
}

public function checkFullTreeCache($actionName, &$httpVars, &$fileVars)
{
$cName = $this->getTreeName();
if (is_file($cName)) {
header('Content-Type: text/xml; charset=UTF-8');
header('Cache-Control: no-cache');
if ( strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') ) {
header('Content-Encoding:deflate');
readfile($cName.".gz");
} else {
readfile($cName);
}
exit();
}
}

public function cacheFullTree($actionName, $httpVars, $postProcessData)
{
$cName = $this->getTreeName();
if(!is_dir(dirname($cName))) mkdir(dirname($cName));
$xmlString = $postProcessData["ob_output"];
file_put_contents($cName, $xmlString);
file_put_contents($cName.".gz", gzdeflate($xmlString, 9));
print($xmlString);
}

public function switchActions($actionName, $httpVars, $fileVars)
{
//$urlBase = $this->accessDriver
Expand Down Expand Up @@ -161,11 +207,20 @@ public function getFileHash($node)
}
}

/**
* @param AJXP_Node $oldNode
* @param AJXP_Node $newNode
* @param bool $copy
*/
public function invalidateHash($oldNode = null, $newNode = null, $copy = false)
{
if($this->metaStore == false) return;
if($oldNode == null) return;
$this->metaStore->removeMetadata($oldNode, FileHasher::METADATA_HASH_NAMESPACE, false, AJXP_METADATA_SCOPE_GLOBAL);
if ($oldNode != null) {
$this->metaStore->removeMetadata($oldNode, FileHasher::METADATA_HASH_NAMESPACE, false, AJXP_METADATA_SCOPE_GLOBAL);
}
if ($this->getFilteredOption("CACHE_XML_TREE") === true && is_file($this->getTreeName())) {
@unlink($this->getTreeName());
}
}


Expand Down
11 changes: 11 additions & 0 deletions core/src/plugins/meta.filehasher/manifest.xml
Expand Up @@ -2,6 +2,9 @@
<meta id="meta.filehasher" label="CONF_MESSAGE[File Hasher]" description="CONF_MESSAGE[Compute on-demand a hash of the file content and stores it in the metadata if a metastore is provided]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
<class_definition filename="plugins/meta.filehasher/class.FileHasher.php" classname="FileHasher"/>
<server_settings>
<param name="CACHE_XML_TREE" type="boolean" default="false" label="Cache full tree" description="Cache XML tree and invalidate on node change"/>
</server_settings>
<client_settings>
<resources>
<i18n namespace="meta.filehasher" path="plugins/meta.filehasher/i18n" />
Expand All @@ -27,6 +30,14 @@
<serverCallback methodName="switchActions"/>
</processing>
</action>
<action name="ls">
<pre_processing>
<serverCallback methodName="checkFullTreeCache" applyCondition="$apply=isSet($httpVars['recursive']);"/>
</pre_processing>
<post_processing>
<serverCallback methodName="cacheFullTree" capture="true" applyCondition="$apply=isSet($httpVars['recursive']);"/>
</post_processing>
</action>
</actions>
<hooks>
<serverCallback hookName="node.info" methodName="getFileHash" applyCondition="$apply = isSet($_GET['recursive']);"/>
Expand Down
7 changes: 4 additions & 3 deletions core/src/plugins/meta.syncable/class.ChangesTracker.php
Expand Up @@ -102,11 +102,12 @@ public function switchActions($actionName, $httpVars, $fileVars)
* @param Repository $repository
* @return String
*/
protected function computeIdentifier($repository){
protected function computeIdentifier($repository)
{
$parts = array($repository->getId());
if($repository->securityScope() == 'USER'){
if ($repository->securityScope() == 'USER') {
$parts[] = AuthService::getLoggedUser()->getId();
}else if($repository->securityScope() == 'GROUP'){
} else if ($repository->securityScope() == 'GROUP') {
$parts[] = AuthService::getLoggedUser()->getGroupPath();
}
return implode("-", $parts);
Expand Down

0 comments on commit 9cd5c10

Please sign in to comment.