diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-06-18 22:04:56 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-31 15:55:40 +0100 |
commit | 3692769b0a0713fa9e3976692736da76707986c5 (patch) | |
tree | 7749b3fcc18a8027301635519794a44b9bdc683e /lib/private | |
parent | 357a823457397d3e93ec8cd4dc01fb6859eb0049 (diff) | |
download | nextcloud-server-3692769b0a0713fa9e3976692736da76707986c5.tar.gz nextcloud-server-3692769b0a0713fa9e3976692736da76707986c5.zip |
Add getShareTypesInFolder to optimize folder listening
Signed-off-by: Robin Appelman <icewind@owncloud.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 43 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 10 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 4 |
3 files changed, 57 insertions, 0 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 56b9d5b1ee8..2002e3bf8cb 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -454,6 +454,49 @@ class DefaultShareProvider implements IShareProvider { return $share; } + public function getSharesInFolder($userId, $node, $reshares) { + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('*') + ->from('share', 's') + ->andWhere($qb->expr()->orX( + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) + )); + + $qb->andWhere($qb->expr()->orX( + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) + )); + + /** + * Reshares for this user are shares where they are the owner. + */ + if ($reshares === false) { + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); + } else { + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) + ) + ); + } + + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); + + $qb->orderBy('id'); + + $cursor = $qb->execute(); + $shares = []; + while ($data = $cursor->fetch()) { + $shares[$data['fileid']][] = $this->createShare($data); + } + $cursor->closeCursor(); + + return $shares; + } + /** * @inheritdoc */ diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 22cf5a3f65a..f2f4acf8d00 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -34,6 +34,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountManager; +use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IGroupManager; @@ -48,6 +49,7 @@ use OCP\Share\IManager; use OCP\Share\IProviderFactory; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; +use OCP\Share\IShareProvider; /** * This class is the communication hub for all sharing related operations. @@ -881,6 +883,14 @@ class Manager implements IManager { $provider->move($share, $recipientId); } + public function getSharesInFolder($userId, Node $node, $reshares = false) { + $providers = $this->factory->getAllProviders(); + + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { + return $shares + $provider->getSharesInFolder($userId, $node, $reshares); + }, []); + } + /** * @inheritdoc */ diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index e3de10a8aee..5cdc9a51a22 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -163,4 +163,8 @@ class ProviderFactory implements IProviderFactory { return $provider; } + + public function getAllProviders() { + return [$this->defaultShareProvider(), $this->federatedShareProvider()]; + } } |