Cache: split permission cache scanning and cache scanning

This commit is contained in:
Robin Appelman 2013-01-07 01:03:11 +01:00
parent 457dc270f5
commit 439578288f
3 changed files with 23 additions and 17 deletions

View File

@ -24,11 +24,6 @@ class Scanner {
*/
private $cache;
/**
* @var \OC\Files\Cache\Permissions $permissionsCache
*/
private $permissionsCache;
const SCAN_RECURSIVE = true;
const SCAN_SHALLOW = false;
@ -36,7 +31,6 @@ class Scanner {
$this->storage = $storage;
$this->storageId = $this->storage->getId();
$this->cache = $storage->getCache();
$this->permissionsCache = $storage->getPermissionsCache();
}
/**
@ -53,10 +47,8 @@ class Scanner {
$data['mtime'] = $this->storage->filemtime($path);
if ($data['mimetype'] == 'httpd/unix-directory') {
$data['size'] = -1; //unknown
$data['permissions'] = $this->storage->getPermissions($path . '/');
} else {
$data['size'] = $this->storage->filesize($path);
$data['permissions'] = $this->storage->getPermissions($path);
}
return $data;
}
@ -81,7 +73,6 @@ class Scanner {
}
}
$id = $this->cache->put($file, $data);
$this->permissionsCache->set($id, \OC_User::getUser(), $data['permissions']);
}
return $data;
}

View File

@ -680,6 +680,8 @@ class View {
list($storage, $internalPath) = Filesystem::resolvePath($path);
if ($storage) {
$cache = $storage->getCache($internalPath);
$permissionsCache = $storage->getPermissionsCache($internalPath);
$user = \OC_User::getUser();
if (!$cache->inCache($internalPath)) {
$scanner = $storage->getScanner($internalPath);
@ -705,8 +707,12 @@ class View {
}
}
$permissionsCache = $storage->getPermissionsCache($internalPath);
$data['permissions'] = $permissionsCache->get($data['fileid'], \OC_User::getUser());
$permissions = $permissionsCache->get($data['fileid'], $user);
if ($permissions === -1) {
$permissions = $storage->getPermissions($internalPath);
$permissionsCache->set($data['fileid'], $user, $permissions);
}
$data['permissions'] = $permissions;
}
}
return $data;
@ -728,6 +734,8 @@ class View {
list($storage, $internalPath) = Filesystem::resolvePath($path);
if ($storage) {
$cache = $storage->getCache($internalPath);
$permissionsCache = $storage->getPermissionsCache($internalPath);
$user = \OC_User::getUser();
if ($cache->getStatus($internalPath) < Cache\Cache::COMPLETE) {
$scanner = $storage->getScanner($internalPath);
@ -743,12 +751,13 @@ class View {
foreach ($files as $i => $file) {
$files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$ids[] = $file['fileid'];
}
$permissionsCache = $storage->getPermissionsCache($internalPath);
$permissions = $permissionsCache->getMultiple($ids, \OC_User::getUser());
foreach ($files as $i => $file) {
$files[$i]['permissions'] = $permissions[$file['fileid']];
$permissions = $permissionsCache->get($file['fileid'], $user);
if ($permissions === -1) {
$permissions = $storage->getPermissions($file['path']);
$permissionsCache->set($file['fileid'], $user, $permissions);
}
$files[$i]['permissions'] = $permissions;
}
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
@ -772,7 +781,12 @@ class View {
$rootEntry['name'] = $relativePath;
$rootEntry['type'] = $rootEntry['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$subPermissionsCache = $subStorage->getPermissionsCache('');
$rootEntry['permissions'] = $subPermissionsCache->get($rootEntry['fileid'], \OC_User::getUser());
$permissions = $subPermissionsCache->get($rootEntry['fileid'], $user);
if ($permissions === -1) {
$permissions = $subStorage->getPermissions($rootEntry['path']);
$subPermissionsCache->set($rootEntry['fileid'], $user, $permissions);
}
$rootEntry['permissions'] = $subPermissionsCache;
$files[] = $rootEntry;
}
}

View File

@ -43,6 +43,7 @@ class View extends \PHPUnit_Framework_TestCase {
$cachedData = $rootView->getFileInfo('/foo.txt');
$this->assertEquals($textSize, $cachedData['size']);
$this->assertEquals('text/plain', $cachedData['mimetype']);
$this->assertEquals(\OCP\PERMISSION_ALL ^ \OCP\PERMISSION_CREATE, $cachedData['permissions']);
$cachedData = $rootView->getFileInfo('/');
$this->assertEquals($storageSize * 3, $cachedData['size']);