diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-10-31 19:28:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-31 19:28:29 +0100 |
commit | fd475d421232e3d83103304002bce23a0b267a60 (patch) | |
tree | f7ccb86835b1bf8b6767368be9e0d62135c1a062 /lib | |
parent | ef6806a23579c50ff9740662aec17ae2551a2f86 (diff) | |
parent | 2f49806c201c0aaaf400e84a7580d0789c90dc57 (diff) | |
download | nextcloud-server-fd475d421232e3d83103304002bce23a0b267a60.tar.gz nextcloud-server-fd475d421232e3d83103304002bce23a0b267a60.zip |
Merge pull request #17739 from nextcloud/enh/share/filter
Get all shares iterable
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 26 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 7 | ||||
-rw-r--r-- | lib/public/Share/IManager.php | 12 | ||||
-rw-r--r-- | lib/public/Share/IShareProvider.php | 9 |
4 files changed, 54 insertions, 0 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index aea50dfcdb6..05b3094e6a2 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -1382,4 +1382,30 @@ class DefaultShareProvider implements IShareProvider { } } + + public function getAllShares(): iterable { + $qb = $this->dbConn->getQueryBuilder(); + + $qb->select('*') + ->from('share') + ->where( + $qb->expr()->orX( + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_USER)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_GROUP)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_LINK)) + ) + ); + + $cursor = $qb->execute(); + while($data = $cursor->fetch()) { + try { + $share = $this->createShare($data); + } catch (InvalidShare $e) { + continue; + } + + yield $share; + } + $cursor->closeCursor(); + } } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 2e8e6f9a3af..df537062e4a 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1671,4 +1671,11 @@ class Manager implements IManager { return true; } + public function getAllShares(): iterable { + $providers = $this->factory->getAllProviders(); + + foreach ($providers as $provider) { + yield from $provider->getAllShares(); + } + } } diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 302be523327..8bb7291d6ba 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -385,4 +385,16 @@ interface IManager { */ public function shareProviderExists($shareType); + /** + * @Internal + * + * Get all the shares as iterable to reduce memory overhead + * Note, since this opens up database cursors the iterable should + * be fully itterated. + * + * @return iterable + * @since 18.0.0 + */ + public function getAllShares(): iterable; + } diff --git a/lib/public/Share/IShareProvider.php b/lib/public/Share/IShareProvider.php index 6731bf8882b..c8815928269 100644 --- a/lib/public/Share/IShareProvider.php +++ b/lib/public/Share/IShareProvider.php @@ -217,4 +217,13 @@ interface IShareProvider { * @since 12 */ public function getAccessList($nodes, $currentAccess); + + /** + * Get all the shares in this provider returned as iterable to reduce memory + * overhead + * + * @return iterable + * @since 18.0.0 + */ + public function getAllShares(): iterable; } |