diff options
-rw-r--r-- | apps/federatedfilesharing/lib/FederatedShareProvider.php | 27 | ||||
-rw-r--r-- | apps/sharebymail/lib/ShareByMailProvider.php | 25 | ||||
-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 | 11 | ||||
-rw-r--r-- | lib/public/Share/IShareProvider.php | 8 |
6 files changed, 104 insertions, 0 deletions
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index 67089cba9d3..4d93dec18f7 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -1100,4 +1100,31 @@ class FederatedShareProvider implements IShareProvider { return ['remote' => $remote]; } + + public function getAllShares(): iterable { + $qb = $this->dbConnection->getQueryBuilder(); + + $qb->select('*') + ->from('share') + ->where( + $qb->expr()->orX( + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_REMOTE)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_REMOTE_GROUP)) + ) + ); + + $cursor = $qb->execute(); + while($data = $cursor->fetch()) { + try { + $share = $this->createShareObject($data); + } catch (InvalidShare $e) { + continue; + } catch (ShareNotFound $e) { + continue; + } + + yield $share; + } + $cursor->closeCursor(); + } } diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 9bfe5e733f4..903df175e9c 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -1166,4 +1166,29 @@ class ShareByMailProvider implements IShareProvider { return ['public' => $mail]; } + public function getAllShares(): iterable { + $qb = $this->dbConnection->getQueryBuilder(); + + $qb->select('*') + ->from('share') + ->where( + $qb->expr()->orX( + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_EMAIL)) + ) + ); + + $cursor = $qb->execute(); + while($data = $cursor->fetch()) { + try { + $share = $this->createShareObject($data); + } catch (InvalidShare $e) { + continue; + } catch (ShareNotFound $e) { + continue; + } + + yield $share; + } + $cursor->closeCursor(); + } } 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..0c47eb730fd 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -385,4 +385,15 @@ 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 + */ + public function getAllShares(): iterable; + } diff --git a/lib/public/Share/IShareProvider.php b/lib/public/Share/IShareProvider.php index 6731bf8882b..da29a7b98aa 100644 --- a/lib/public/Share/IShareProvider.php +++ b/lib/public/Share/IShareProvider.php @@ -217,4 +217,12 @@ 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 + */ + public function getAllShares(): iterable; } |