Skip to content

Commit

Permalink
Move all children of a folder in a single query
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Feb 6, 2015
1 parent 9898db8 commit 8fb35ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function load($class) {

foreach ($pathsToRequire as $fullPath) {
require_once $fullPath;
return true;
}

return false;
Expand Down
20 changes: 8 additions & 12 deletions lib/private/files/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function get($file) {
$where = 'WHERE `fileid` = ?';
$params = array($file);
}
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
$sql = 'SELECT `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
`storage_mtime`, `encrypted`, `unencrypted_size`, `etag`, `permissions`
FROM `*PREFIX*filecache` ' . $where;
$result = \OC_DB::executeAudited($sql, $params);
Expand Down Expand Up @@ -403,20 +403,16 @@ public function move($source, $target) {
$newParentId = $this->getParentId($target);

if ($sourceData['mimetype'] === 'httpd/unix-directory') {
//find all child entries
$sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?';
$result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId(), $source . '/%'));
$childEntries = $result->fetchAll();
//update all child entries
$sourceLength = strlen($source);
$query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?');

foreach ($childEntries as $child) {
$targetPath = $target . substr($child['path'], $sourceLength);
\OC_DB::executeAudited($query, array($targetPath, md5($targetPath), $child['fileid']));
}
$query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET
`path_hash` = MD5(CONCAT(?, SUBSTR(`path`, ?))),
`path` = CONCAT(?, SUBSTR(`path`, ?))
WHERE `storage` = ? AND `path` LIKE ?');
\OC_DB::executeAudited($query, [$target, $sourceLength + 1,$target, $sourceLength + 1, $this->getNumericStorageId(), $source . '/%']);
}

$sql = 'UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?';
$sql = 'UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` = ? WHERE `fileid` = ?';
\OC_DB::executeAudited($sql, array($target, md5($target), basename($target), $newParentId, $sourceId));
}

Expand Down

0 comments on commit 8fb35ac

Please sign in to comment.