refactor: remove non-shallow getSharesInFolderstorage-cache-not-exists
@@ -578,6 +578,10 @@ class FederatedShareProvider implements IShareProvider { | |||
public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) { | |||
if (!$shallow) { | |||
throw new \Exception("non-shallow getSharesInFolder is no longer supported"); | |||
} | |||
$qb = $this->dbConnection->getQueryBuilder(); | |||
$qb->select('*') | |||
->from('share', 's') | |||
@@ -605,12 +609,7 @@ class FederatedShareProvider implements IShareProvider { | |||
$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); | |||
$qb->andWhere($qb->expr()->eq('f.storage', $qb->createNamedParameter($node->getMountPoint()->getNumericStorageId(), IQueryBuilder::PARAM_INT))); | |||
if ($shallow) { | |||
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId(), IQueryBuilder::PARAM_INT))); | |||
} else { | |||
$qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%'))); | |||
} | |||
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); | |||
$qb->orderBy('id'); | |||
@@ -26,9 +26,11 @@ | |||
*/ | |||
namespace OCA\Files_Sharing; | |||
use OC\Files\Cache\FileAccess; | |||
use OC\Files\Mount\MountPoint; | |||
use OCP\Constants; | |||
use OCP\Files\Folder; | |||
use OCP\Server; | |||
use OCP\Share\IShare; | |||
class Updater { | |||
@@ -58,20 +60,40 @@ class Updater { | |||
if ($userFolder === null) { | |||
return; | |||
} | |||
$user = $userFolder->getOwner(); | |||
if (!$user) { | |||
throw new \Exception("user folder has no owner"); | |||
} | |||
$src = $userFolder->get($path); | |||
$shareManager = \OC::$server->getShareManager(); | |||
// FIXME: should CIRCLES be included here ?? | |||
$shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1); | |||
$shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1)); | |||
$shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1)); | |||
$shares = $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER, $src, false, -1); | |||
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP, $src, false, -1)); | |||
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM, $src, false, -1)); | |||
if ($src instanceof Folder) { | |||
$subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false, false); | |||
$cacheAccess = Server::get(FileAccess::class); | |||
$sourceStorageId = $src->getStorage()->getCache()->getNumericStorageId(); | |||
$sourceInternalPath = $src->getInternalPath(); | |||
$subShares = array_merge( | |||
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER), | |||
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP), | |||
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM), | |||
); | |||
$shareSourceIds = array_map(fn (IShare $share) => $share->getNodeId(), $subShares); | |||
$shareSources = $cacheAccess->getByFileIdsInStorage($shareSourceIds, $sourceStorageId); | |||
foreach ($subShares as $subShare) { | |||
$shares = array_merge($shares, array_values($subShare)); | |||
$shareCacheEntry = $shareSources[$subShare->getNodeId()] ?? null; | |||
if ( | |||
$shareCacheEntry && | |||
str_starts_with($shareCacheEntry->getPath(), $sourceInternalPath . '/') | |||
) { | |||
$shares[] = $subShare; | |||
} | |||
} | |||
} | |||
@@ -1069,12 +1069,7 @@ class ShareByMailProvider implements IShareProvider { | |||
$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); | |||
$qb->andWhere($qb->expr()->eq('f.storage', $qb->createNamedParameter($node->getMountPoint()->getNumericStorageId(), IQueryBuilder::PARAM_INT))); | |||
if ($shallow) { | |||
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); | |||
} else { | |||
$qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%'))); | |||
} | |||
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); | |||
$qb->orderBy('id'); | |||
@@ -652,6 +652,10 @@ class DefaultShareProvider implements IShareProvider { | |||
} | |||
public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) { | |||
if (!$shallow) { | |||
throw new \Exception("non-shallow getSharesInFolder is no longer supported"); | |||
} | |||
$qb = $this->dbConn->getQueryBuilder(); | |||
$qb->select('s.*', | |||
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', | |||
@@ -692,28 +696,12 @@ class DefaultShareProvider implements IShareProvider { | |||
}, $childMountNodes); | |||
$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); | |||
$storageFilter = $qb->expr()->eq('f.storage', $qb->createNamedParameter($node->getMountPoint()->getNumericStorageId(), IQueryBuilder::PARAM_INT)); | |||
if ($shallow) { | |||
$qb->andWhere( | |||
$qb->expr()->orX( | |||
$qb->expr()->andX( | |||
$storageFilter, | |||
$qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())), | |||
), | |||
$qb->expr()->in('f.fileid', $qb->createParameter('chunk')) | |||
) | |||
); | |||
} else { | |||
$qb->andWhere( | |||
$qb->expr()->orX( | |||
$qb->expr()->andX( | |||
$storageFilter, | |||
$qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConn->escapeLikeParameter($node->getInternalPath()) . '/%')), | |||
), | |||
$qb->expr()->in('f.fileid', $qb->createParameter('chunk')) | |||
) | |||
); | |||
} | |||
$qb->andWhere( | |||
$qb->expr()->orX( | |||
$qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())), | |||
$qb->expr()->in('f.fileid', $qb->createParameter('chunk')) | |||
) | |||
); | |||
$qb->orderBy('id'); | |||
@@ -1276,9 +1276,12 @@ class Manager implements IManager { | |||
public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true) { | |||
$providers = $this->factory->getAllProviders(); | |||
if (!$shallow) { | |||
throw new \Exception("non-shallow getSharesInFolder is no longer supported"); | |||
} | |||
return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares, $shallow) { | |||
$newShares = $provider->getSharesInFolder($userId, $node, $reshares, $shallow); | |||
$newShares = $provider->getSharesInFolder($userId, $node, $reshares); | |||
foreach ($newShares as $fid => $data) { | |||
if (!isset($shares[$fid])) { | |||
$shares[$fid] = []; |