Skip to content

Commit

Permalink
show used space in user list
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Jun 15, 2017
1 parent a74901f commit 2e8e6f9
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 167 deletions.
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);
}
}
11 changes: 11 additions & 0 deletions lib/public/Files/Config/IUserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,15 @@ 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]
*/
public function getUsedSpaceForUsers(array $users);
}
Loading

0 comments on commit 2e8e6f9

Please sign in to comment.