diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 34 | ||||
-rw-r--r-- | lib/public/Files/Config/IUserMountCache.php | 12 |
2 files changed, 44 insertions, 2 deletions
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 6ec78e4d81c..80cedfa1ccd 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -24,6 +24,7 @@ namespace OC\Files\Config; +use OC\DB\QueryBuilder\Literal; use OCA\Files_Sharing\SharedMount; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Config\ICachedMountInfo; @@ -193,7 +194,7 @@ class UserMountCache implements IUserMountCache { if (is_null($user)) { return null; } - return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id'], isset($row['path'])? $row['path']:''); + return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id'], isset($row['path']) ? $row['path'] : ''); } /** @@ -224,7 +225,7 @@ class UserMountCache implements IUserMountCache { $builder = $this->connection->getQueryBuilder(); $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') ->from('mounts', 'm') - ->innerJoin('m', 'filecache', 'f' , $builder->expr()->eq('m.root_id', 'f.fileid')) + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); if ($user) { @@ -332,4 +333,33 @@ class UserMountCache implements IUserMountCache { ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); $query->execute(); } + + public function getUsedSpaceForUsers(array $users) { + $builder = $this->connection->getQueryBuilder(); + + $slash = $builder->createNamedParameter('/'); + + $mountPoint = $builder->func()->concat( + $builder->func()->concat($slash, 'user_id'), + $slash + ); + + $userIds = array_map(function (IUser $user) { + return $user->getUID(); + }, $users); + + $query = $builder->select('m.user_id', 'f.size') + ->from('mounts', 'm') + ->innerJoin('m', 'filecache', 'f', + $builder->expr()->andX( + $builder->expr()->eq('m.storage_id', 'f.storage'), + $builder->expr()->eq('f.path', $builder->createNamedParameter('files')) + )) + ->where($builder->expr()->eq('m.mount_point', $mountPoint)) + ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); + + $result = $query->execute(); + + return $result->fetchAll(\PDO::FETCH_KEY_PAIR); + } } diff --git a/lib/public/Files/Config/IUserMountCache.php b/lib/public/Files/Config/IUserMountCache.php index cf30d8fb431..fca797d3b69 100644 --- a/lib/public/Files/Config/IUserMountCache.php +++ b/lib/public/Files/Config/IUserMountCache.php @@ -104,4 +104,16 @@ interface IUserMountCache { * @since 9.0.0 */ public function remoteStorageMounts($storageId); + + /** + * Get the used space for users + * + * Note that this only includes the space in their home directory, + * not any incoming shares or external storages. + * + * @param IUser[] $users + * @return int[] [$userId => $userSpace] + * @since 13.0.0 + */ + public function getUsedSpaceForUsers(array $users); } |