Permalink
Browse files

ChangeTracker: Implement a method to compute size recursively. Use ta…

…sks to trigger indexations in background.
  • Loading branch information...
1 parent 85e7545 commit 41a694984bd733ae4183a14029fed051586bf30f @cdujeu cdujeu committed Jun 2, 2016
@@ -31,6 +31,8 @@
use Pydio\Core\Utils\TextEncoder;
use Pydio\Log\Core\AJXP_Logger;
use Pydio\Meta\Core\AJXP_AbstractMetaSource;
+use Pydio\Tasks\Schedule;
+use Pydio\Tasks\TaskService;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -228,11 +230,8 @@ public function switchActions($actionName, $httpVars, $fileVars)
}
}
if($this->options["REQUIRES_INDEXATION"]){
- if (ConfService::backgroundActionsSupported()){
- Controller::applyActionInBackground(ConfService::getRepository()->getId(), "index", array());
- }else{
- Controller::findActionAndApply("index", array(), array());
- }
+ $task = TaskService::actionAsTask("index", []);
+ TaskService::getInstance()->enqueueTask($task);
// Unset the REQUIRES_INDEXATION FLAG
$meta = $currentRepo->getOption("META_SOURCES");
unset($meta["meta.syncable"]["REQUIRES_INDEXATION"]);
@@ -534,8 +533,11 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
"repository_identifier" => $repoId = $this->computeIdentifier($newNode->getRepository(), $newNode->getUser())
));
if($copy && !$newNode->isLeaf()){
- // Make sure to index the content of this file
- Controller::findActionAndApply("index", array("file" => $newNode->getPath()), array());
+ // Make sure to index the content of this folder
+ $this->logInfo("Core.index", "Should reindex folder ".$newNode->getPath());
+ $task = TaskService::actionAsTask("index", ["file" => $newNode->getPath()]);
+ $task->setSchedule(new Schedule(Schedule::TYPE_ONCE_DEFER));
+ TaskService::getInstance()->enqueueTask($task);
}
} else {
$repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser());
@@ -583,7 +585,10 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
$rowCount = dibi::getAffectedRows();
if($rowCount === 0){
$this->logError(__FUNCTION__, "There was an update event on a non-indexed folder (".$newNode->getPath()."), relaunching a recursive indexation!");
- Controller::findActionAndApply("index", array("file" => $newNode->getPath()), array());
+ $task = TaskService::actionAsTask("index", ["file" => $newNode->getPath()]);
+ $task->setSchedule(new Schedule(Schedule::TYPE_ONCE_DEFER));
+ TaskService::getInstance()->enqueueTask($task);
+
}
}catch (Exception $e){}
}
@@ -598,6 +603,18 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
}
/**
+ * @param AJXP_Node $node
+ * @param integer $result
+ */
+ public function computeSizeRecursive(&$node, &$result){
+
+ $id = $this->computeIdentifier($node->getRepository());
+ $res = dibi::query("SELECT SUM([bytesize]) FROM [ajxp_index] WHERE [repository_identifier] = %s AND ([node_path] = %s OR [node_path] LIKE %s)", $id, $node->getPath(), $node->getPath()."/%");
+ $result = floatval($res->fetchSingle());
+
+ }
+
+ /**
* @param \Pydio\Access\Core\Model\AJXP_Node $node
* @return bool
*/
@@ -35,6 +35,7 @@
<serverCallback hookName="node.change" methodName="updateNodesIndex" defer="true"/>
<serverCallback hookName="node.index" methodName="indexNode"/>
<serverCallback hookName="node.index.recursive.start" methodName="clearIndexForNode"/>
+ <serverCallback hookName="node.size.recursive" methodName="computeSizeRecursive"/>
<serverCallback hookName="workspace.after_delete" methodName="clearIndexForWorkspaceId"/>
<serverCallback hookName="workspace.share_metasources" methodName="setIndexationRequiredFlag"/>
</hooks>

0 comments on commit 41a6949

Please sign in to comment.