]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cache: split permission cache scanning and cache scanning
authorRobin Appelman <icewind@owncloud.com>
Mon, 7 Jan 2013 00:03:11 +0000 (01:03 +0100)
committerRobin Appelman <icewind@owncloud.com>
Mon, 7 Jan 2013 00:03:11 +0000 (01:03 +0100)
lib/files/cache/scanner.php
lib/files/view.php
tests/lib/files/view.php

index 4c0ec9617f91fa029fd9b9dd31bb4bb3238b2105..526d4a2aab5799027f13b4c731f7ca7f524c9bee 100644 (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;
        }
index 9ba3eea3cf9f622d20193565dd5806a64202432c..124345f3c6f7cbbe72acbec5f576be95b274fbf1 100644 (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;
                                        }
                                }
index 712166ab32cf8a4ff6f1babea699aabcdc78b88a..4b0abc2201debd3c287c96c7463955c789351bac 100644 (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']);