cache result from parent folders
This commit is contained in:
parent
7fe047425f
commit
4719305e3b
|
@ -27,6 +27,13 @@ class File implements \OCP\Encryption\IFile {
|
||||||
/** @var Util */
|
/** @var Util */
|
||||||
protected $util;
|
protected $util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cache results of already checked folders
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $cache;
|
||||||
|
|
||||||
public function __construct(Util $util) {
|
public function __construct(Util $util) {
|
||||||
$this->util = $util;
|
$this->util = $util;
|
||||||
}
|
}
|
||||||
|
@ -53,10 +60,24 @@ class File implements \OCP\Encryption\IFile {
|
||||||
$ownerPath = substr($ownerPath, strlen('/files'));
|
$ownerPath = substr($ownerPath, strlen('/files'));
|
||||||
$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
|
$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
|
||||||
|
|
||||||
|
|
||||||
|
// first get the shares for the parent and cache the result so that we don't
|
||||||
|
// need to check all parents for every file
|
||||||
|
$parent = dirname($ownerPath);
|
||||||
|
if (isset($this->cache[$parent])) {
|
||||||
|
$resultForParents = $this->cache[$parent];
|
||||||
|
} else {
|
||||||
|
$resultForParents = \OCP\Share::getUsersSharingFile($parent, $owner);
|
||||||
|
$this->cache[$parent] = $resultForParents;
|
||||||
|
}
|
||||||
|
$userIds = \array_merge($userIds, $resultForParents['users']);
|
||||||
|
$public = $resultForParents['public'] || $resultForParents['remote'];
|
||||||
|
|
||||||
|
|
||||||
// Find out who, if anyone, is sharing the file
|
// Find out who, if anyone, is sharing the file
|
||||||
$result = \OCP\Share::getUsersSharingFile($ownerPath, $owner);
|
$resultForFile = \OCP\Share::getUsersSharingFile($ownerPath, $owner, false, false, false);
|
||||||
$userIds = \array_merge($userIds, $result['users']);
|
$userIds = \array_merge($userIds, $resultForFile['users']);
|
||||||
$public = $result['public'] || $result['remote'];
|
$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
|
||||||
|
|
||||||
// check if it is a group mount
|
// check if it is a group mount
|
||||||
if (\OCP\App::isEnabled("files_external")) {
|
if (\OCP\App::isEnabled("files_external")) {
|
||||||
|
|
|
@ -122,11 +122,12 @@ class Share extends Constants {
|
||||||
* @param string $ownerUser owner of the file
|
* @param string $ownerUser owner of the file
|
||||||
* @param boolean $includeOwner include owner to the list of users with access to the file
|
* @param boolean $includeOwner include owner to the list of users with access to the file
|
||||||
* @param boolean $returnUserPaths Return an array with the user => path map
|
* @param boolean $returnUserPaths Return an array with the user => path map
|
||||||
|
* @param boolean $recursive take all parent folders into account (default true)
|
||||||
* @return array
|
* @return array
|
||||||
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
|
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
|
||||||
* not '/admin/data/file.txt'
|
* not '/admin/data/file.txt'
|
||||||
*/
|
*/
|
||||||
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false) {
|
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
|
||||||
|
|
||||||
Filesystem::initMountPoints($ownerUser);
|
Filesystem::initMountPoints($ownerUser);
|
||||||
$shares = $sharePaths = $fileTargets = array();
|
$shares = $sharePaths = $fileTargets = array();
|
||||||
|
@ -252,7 +253,7 @@ class Share extends Constants {
|
||||||
|
|
||||||
// let's get the parent for the next round
|
// let's get the parent for the next round
|
||||||
$meta = $cache->get((int)$source);
|
$meta = $cache->get((int)$source);
|
||||||
if($meta !== false) {
|
if ($recursive === true && $meta !== false) {
|
||||||
$source = (int)$meta['parent'];
|
$source = (int)$meta['parent'];
|
||||||
} else {
|
} else {
|
||||||
$source = -1;
|
$source = -1;
|
||||||
|
|
|
@ -80,13 +80,14 @@ class Share extends \OC\Share\Constants {
|
||||||
* @param string $ownerUser owner of the file
|
* @param string $ownerUser owner of the file
|
||||||
* @param bool $includeOwner include owner to the list of users with access to the file
|
* @param bool $includeOwner include owner to the list of users with access to the file
|
||||||
* @param bool $returnUserPaths Return an array with the user => path map
|
* @param bool $returnUserPaths Return an array with the user => path map
|
||||||
|
* @param bool $recursive take parent folders into account
|
||||||
* @return array
|
* @return array
|
||||||
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
|
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
|
||||||
* not '/admin/data/file.txt'
|
* not '/admin/files/file.txt'
|
||||||
* @since 5.0.0
|
* @since 5.0.0 - $recursive was added in 8.2.0
|
||||||
*/
|
*/
|
||||||
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false) {
|
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
|
||||||
return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths);
|
return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths, $recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue