Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,7 +194,7 @@ private function dbRowToMountInfo(array $row) {
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'] : '');
}

/**
Expand Down Expand Up @@ -224,7 +225,7 @@ public function getMountsForStorageId($numericStorageId, $user = null) {
$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) {
Expand Down Expand Up @@ -332,4 +333,33 @@ public function remoteStorageMounts($storageId) {
->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);
}
}
12 changes: 12 additions & 0 deletions lib/public/Files/Config/IUserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,16 @@ public function removeUserStorageMount($storageId, $userId);
* @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);
}
Loading