mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
let the share backend get the node cacheentry to save queries
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
065753f0ae
commit
2f03fcab4a
6 changed files with 108 additions and 27 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,25 +142,37 @@ 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue