Skip to content
Open
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: 14 additions & 26 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,35 +219,23 @@ public function getGroupFolderStorage(
if ($user) {
$inShare = !\OC::$CLI && ($this->getCurrentUID() === null || $this->getCurrentUID() !== $user->getUID());
$baseStorage = $this->folderStorageManager->getBaseStorageForFolder($folder->id, $folder->useSeparateStorage(), $folder, $user, $inShare, $type);
} else {
$baseStorage = $this->folderStorageManager->getBaseStorageForFolder($folder->id, $folder->useSeparateStorage(), $folder, null, false, $type);
}

if ($user) {
$baseStorage->setOwner($user->getUID());
}

if ($this->enableEncryption) {
$quotaStorage = new GroupFolderStorage([
'storage' => $baseStorage,
'quota' => $folder->quota,
'folder' => $folder,
'rootCacheEntry' => $rootCacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
} else {
$quotaStorage = new GroupFolderNoEncryptionStorage([
'storage' => $baseStorage,
'quota' => $folder->quota,
'folder' => $folder,
'rootCacheEntry' => $rootCacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
$baseStorage = $this->folderStorageManager->getBaseStorageForFolder($folder->id, $folder->useSeparateStorage(), $folder, null, false, $type);
}

return $quotaStorage;
$storageClass = $this->enableEncryption
? GroupFolderStorage::class
: GroupFolderNoEncryptionStorage::class;

return new $storageClass([
'storage' => $baseStorage,
'quota' => $folder->quota,
'folder' => $folder,
'rootCacheEntry' => $rootCacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
}

/**
Expand All @@ -268,7 +256,7 @@ private function findConflictsForUser(IUser $user, array $mountPoints): array {
$paths = [];
foreach (array_chunk($pathHashes, 1000) as $chunk) {
$query->setParameter('chunk', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$paths = array_merge($paths, $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN));
array_push($paths, ...$query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN));
Comment on lines -271 to +259
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m afraid this may be less efficient, it will expand the whole array into function parameters instead of passing 2 arrays to array_merge. Do you have a reference on why this would be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each call to array_merge() creates a new array by copying all existing elements plus the new ones. array_push() with the spread operator ... appends elements directly to the existing array without creating copies.

However, you might be right that spreading into function parameters isn't ideal.
The optimal approach may be to collect arrays first, then merge once:

$chunks = [];
foreach (array_chunk($pathHashes, 1000) as $chunk) {
	$query->setParameter('chunk', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
	$chunks[] = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
}
$paths = array_merge(...$chunks);

}

return array_map(function (string $path): string {
Expand Down
Loading