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 /lib | |
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>
Diffstat (limited to 'lib')
-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 |
4 files changed, 81 insertions, 19 deletions
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(); } |