Cache: provide a function to get the permissions of all files in a folder with one query
This commit is contained in:
parent
7c0c6bd779
commit
44d217c425
|
@ -85,6 +85,25 @@ class Permissions {
|
|||
return $filePermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the permissions for all files in a folder
|
||||
*
|
||||
* @param int $parentId
|
||||
* @return int[]
|
||||
*/
|
||||
public function getDirectoryPermissions($parentId) {
|
||||
$query = \OC_DB::prepare('SELECT `*PREFIX*permissions`.`fileid`, `permissions`
|
||||
FROM `*PREFIX*permissions` INNER JOIN `*PREFIX*filecache` ON `*PREFIX*permissions`.fileid = `*PREFIX*filecache`.fileid
|
||||
WHERE `*PREFIX*filecache`.parent = ?');
|
||||
|
||||
$result = $query->execute(array($parentId));
|
||||
$filePermissions = array();
|
||||
while ($row = $result->fetchRow()) {
|
||||
$filePermissions[$row['fileid']] = $row['permissions'];
|
||||
}
|
||||
return $filePermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove the permissions for a file
|
||||
*
|
||||
|
|
|
@ -797,18 +797,18 @@ class View {
|
|||
}
|
||||
|
||||
$files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
|
||||
$permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath));
|
||||
|
||||
$ids = array();
|
||||
foreach ($files as $i => $file) {
|
||||
$files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
|
||||
$ids[] = $file['fileid'];
|
||||
|
||||
$permissions = $permissionsCache->get($file['fileid'], $user);
|
||||
if ($permissions === -1) {
|
||||
$permissions = $storage->getPermissions($file['path']);
|
||||
$permissionsCache->set($file['fileid'], $user, $permissions);
|
||||
if (!isset($permissions[$file['fileid']])) {
|
||||
$permissions[$file['fileid']] = $storage->getPermissions($file['path']);
|
||||
$permissionsCache->set($file['fileid'], $user, $permissions[$file['fileid']]);
|
||||
}
|
||||
$files[$i]['permissions'] = $permissions;
|
||||
$files[$i]['permissions'] = $permissions[$file['fileid']];
|
||||
}
|
||||
|
||||
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
|
||||
|
|
Loading…
Reference in New Issue