Skip to content
Closed
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
40 changes: 19 additions & 21 deletions lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ private function removeFromCache(ICachedMountInfo $mount) {
/**
* @param array $row
* @param (callable(CachedMountInfo): string)|null $pathCallback
* @return CachedMountInfo
*/
private function dbRowToMountInfo(array $row, ?callable $pathCallback = null): ICachedMountInfo {
$user = new LazyUser($row['user_id'], $this->userManager);
Expand Down Expand Up @@ -250,10 +249,9 @@ private function dbRowToMountInfo(array $row, ?callable $pathCallback = null): I
}

/**
* @param IUser $user
* @return ICachedMountInfo[]
*/
public function getMountsForUser(IUser $user) {
public function getMountsForUser(IUser $user): array {
$userUID = $user->getUID();
if (!$this->userManager->userExists($userUID)) {
return [];
Expand All @@ -265,18 +263,14 @@ public function getMountsForUser(IUser $user) {
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userUID)));

$result = $query->executeQuery();
$rows = $result->fetchAll();
$result->closeCursor();

/** @var array<string, ICachedMountInfo> $mounts */
$mounts = [];
foreach ($rows as $row) {
$mount = $this->dbRowToMountInfo($row, [$this, 'getInternalPathForMountInfo']);
if ($mount !== null) {
$mounts[$mount->getKey()] = $mount;
}
foreach ($result->iterateAssociative() as $row) {
$mount = $this->dbRowToMountInfo($row, $this->getInternalPathForMountInfo(...));
$mounts[$mount->getKey()] = $mount;
}
$this->mountsForUsers[$userUID] = $mounts;
$result->closeCursor();
}
return $this->mountsForUsers[$userUID];
}
Expand All @@ -296,9 +290,9 @@ public function getInternalPathForMountInfo(CachedMountInfo $info): string {
/**
* @param int $numericStorageId
* @param string|null $user limit the results to a single user
* @return CachedMountInfo[]
* @return list<ICachedMountInfo>
*/
public function getMountsForStorageId($numericStorageId, $user = null) {
public function getMountsForStorageId($numericStorageId, $user = null): array {
$builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
->from('mounts', 'm')
Expand All @@ -310,28 +304,32 @@ public function getMountsForStorageId($numericStorageId, $user = null) {
}

$result = $query->executeQuery();
$rows = $result->fetchAll();
$mounts = [];
foreach ($result->iterateAssociative() as $row) {
$mounts[] = $this->dbRowToMountInfo($row);
}
$result->closeCursor();

return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
return $mounts;
}

/**
* @param int $rootFileId
* @return CachedMountInfo[]
* @return list<ICachedMountInfo>
*/
public function getMountsForRootId($rootFileId) {
public function getMountsForRootId($rootFileId): array {
$builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
->from('mounts', 'm')
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
->where($builder->expr()->eq('root_id', $builder->createNamedParameter($rootFileId, IQueryBuilder::PARAM_INT)));

$result = $query->executeQuery();
$rows = $result->fetchAll();
$mounts = [];
foreach ($result->iterateAssociative() as $row) {
$mounts[] = $this->dbRowToMountInfo($row);
}
$result->closeCursor();

return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
return $mounts;
}

/**
Expand Down
Loading