diff options
author | Robin Appelman <robin@icewind.nl> | 2016-11-17 14:18:47 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-11-17 18:48:38 +0100 |
commit | 2f03fcab4af43de3ee5e0b25aa7aa18ca8f4c4db (patch) | |
tree | 9c858a653a582197d02af31d182e89e3df971d53 | |
parent | 065753f0ae39cfee229cefb612ca8243b9bae6ca (diff) | |
download | nextcloud-server-2f03fcab4af43de3ee5e0b25aa7aa18ca8f4c4db.tar.gz nextcloud-server-2f03fcab4af43de3ee5e0b25aa7aa18ca8f4c4db.zip |
let the share backend get the node cacheentry to save queries
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | apps/files_sharing/lib/MountProvider.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedStorage.php | 32 | ||||
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 44 | ||||
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 21 | ||||
-rw-r--r-- | lib/private/Share20/Share.php | 18 | ||||
-rw-r--r-- | lib/public/Share/IShare.php | 17 |
6 files changed, 108 insertions, 27 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 1ee6f2b35f6..40d2fb27535 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -172,6 +172,9 @@ class MountProvider implements IMountProvider { $share->setTarget($superShare->getTarget()); $this->shareManager->moveShare($share, $user->getUID()); } + if (!is_null($share->getNodeCacheEntry())) { + $superShare->setNodeCacheEntry($share->getNodeCacheEntry()); + } } $superShare->setPermissions($permissions); diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 7002d388d93..86209f6f744 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -71,6 +71,8 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto */ private $logger; + private $options; + public function __construct($arguments) { $this->ownerView = $arguments['ownerView']; $this->logger = \OC::$server->getLogger(); @@ -86,6 +88,20 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto ]); } + /** + * @return ICacheEntry + */ + private function getSourceRootInfo() { + if (is_null($this->sourceRootInfo)) { + if (is_null($this->superShare->getNodeCacheEntry())) { + $this->sourceRootInfo = $this->storage->getCache()->get($this->rootPath); + } else { + $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); + } + } + return $this->sourceRootInfo; + } + private function init() { if ($this->initialized) { return; @@ -95,7 +111,6 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto Filesystem::initMountPoints($this->superShare->getShareOwner()); $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); list($this->storage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); - $this->sourceRootInfo = $this->storage->getCache()->get($this->rootPath); } catch (NotFoundException $e) { $this->storage = new FailedStorage(['exception' => $e]); $this->rootPath = ''; @@ -110,6 +125,9 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto * @inheritdoc */ public function instanceOfStorage($class) { + if ($class === '\OC\Files\Storage\Common') { + return true; + } if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { return false; } @@ -124,8 +142,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto } private function isValid() { - $this->init(); - return $this->sourceRootInfo && ($this->sourceRootInfo->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; + return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; } /** @@ -314,14 +331,10 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto if ($this->cache) { return $this->cache; } - $this->init(); - if (is_null($this->storage) || $this->storage instanceof FailedStorage) { - return new FailedCache(false); - } if (!$storage) { $storage = $this; } - $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->storage, $this->sourceRootInfo); + $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare); return $this->cache; } @@ -449,4 +462,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto return parent::file_put_contents($path, $data); } + public function setMountOptions(array $options) { + $this->mountOptions = $options; + } } diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 5083b99b862..3a3f51488e6 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -142,26 +142,38 @@ class Cache implements ICache { } return $data; } else { - //fix types - $data['fileid'] = (int)$data['fileid']; - $data['parent'] = (int)$data['parent']; - $data['size'] = 0 + $data['size']; - $data['mtime'] = (int)$data['mtime']; - $data['storage_mtime'] = (int)$data['storage_mtime']; - $data['encryptedVersion'] = (int)$data['encrypted']; - $data['encrypted'] = (bool)$data['encrypted']; - $data['storage'] = $this->storageId; - $data['mimetype'] = $this->mimetypeLoader->getMimetypeById($data['mimetype']); - $data['mimepart'] = $this->mimetypeLoader->getMimetypeById($data['mimepart']); - if ($data['storage_mtime'] == 0) { - $data['storage_mtime'] = $data['mtime']; - } - $data['permissions'] = (int)$data['permissions']; - return new CacheEntry($data); + return self::cacheEntryFromData($data, $this->storageId, $this->mimetypeLoader); } } /** + * Create a CacheEntry from database row + * + * @param array $data + * @param string $storageId + * @param IMimeTypeLoader $mimetypeLoader + * @return CacheEntry + */ + public static function cacheEntryFromData($data, $storageId, IMimeTypeLoader $mimetypeLoader) { + //fix types + $data['fileid'] = (int)$data['fileid']; + $data['parent'] = (int)$data['parent']; + $data['size'] = 0 + $data['size']; + $data['mtime'] = (int)$data['mtime']; + $data['storage_mtime'] = (int)$data['storage_mtime']; + $data['encryptedVersion'] = (int)$data['encrypted']; + $data['encrypted'] = (bool)$data['encrypted']; + $data['storage'] = $storageId; + $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); + $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); + if ($data['storage_mtime'] == 0) { + $data['storage_mtime'] = $data['mtime']; + } + $data['permissions'] = (int)$data['permissions']; + return new CacheEntry($data); + } + + /** * get the metadata of all files stored in $folder * * @param string $folder diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index bdb6ac466ec..ccb5b363685 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -23,6 +23,8 @@ */ namespace OC\Share20; +use OC\Files\Cache\Cache; +use OC\Files\Cache\CacheEntry; use OCP\Files\File; use OCP\Files\Folder; use OCP\Share\IShareProvider; @@ -571,7 +573,7 @@ class DefaultShareProvider implements IShareProvider { $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) )); - + $cursor = $qb->execute(); $data = $cursor->fetch(); $cursor->closeCursor(); @@ -656,7 +658,11 @@ class DefaultShareProvider implements IShareProvider { if ($shareType === \OCP\Share::SHARE_TYPE_USER) { //Get shares directly with this user $qb = $this->dbConn->getQueryBuilder(); - $qb->select('s.*', 'f.fileid', 'f.path') + $qb->select('s.*', + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' + ) ->selectAlias('st.id', 'storage_string_id') ->from('share', 's') ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) @@ -798,7 +804,7 @@ class DefaultShareProvider implements IShareProvider { return $share; } - + /** * Create a share object from an database row * @@ -838,6 +844,15 @@ class DefaultShareProvider implements IShareProvider { $share->setExpirationDate($expiration); } + if (isset($data['f_permissions'])) { + $entryData = $data; + $entryData['permissions'] = $entryData['f_permissions']; + $entryData['parent'] = $entryData['f_parent'];; + $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, + $entryData['storage_string_id'], + \OC::$server->getMimeTypeLoader())); + } + $share->setProviderId($this->identifier()); return $share; diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index e3e8482f4e1..2e7e6d0ca2e 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -22,6 +22,7 @@ */ namespace OC\Share20; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\File; use OCP\Files\IRootFolder; use OCP\Files\Node; @@ -72,6 +73,9 @@ class Share implements \OCP\Share\IShare { /** @var IUserManager */ private $userManager; + /** @var ICacheEntry|null */ + private $nodeCacheEntry; + public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { $this->rootFolder = $rootFolder; $this->userManager = $userManager; @@ -418,4 +422,18 @@ class Share implements \OCP\Share\IShare { public function getMailSend() { return $this->mailSend; } + + /** + * @inheritdoc + */ + public function setNodeCacheEntry(ICacheEntry $entry) { + $this->nodeCacheEntry = $entry; + } + + /** + * @inheritdoc + */ + public function getNodeCacheEntry() { + return $this->nodeCacheEntry; + } } diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index 206b0e286a2..5b552b51c3c 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -22,6 +22,7 @@ namespace OCP\Share; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\Node; @@ -324,4 +325,20 @@ interface IShare { * @since 9.0.0 */ public function getMailSend(); + + /** + * Set the cache entry for the shared node + * + * @param ICacheEntry $entry + * @since 11.0.0 + */ + public function setNodeCacheEntry(ICacheEntry $entry); + + /** + * Get the cache entry for the shared node + * + * @return null|ICacheEntry + * @since 11.0.0 + */ + public function getNodeCacheEntry(); } |