Skip to content

Commit

Permalink
lighter request on circle memberships
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Jan 28, 2025
1 parent 3b251ea commit 82f40cf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,15 @@ public function getFoldersFromCircleMemberships(IUser $user, int $rootStorageId
'group_folders_groups',
'a',
$query->expr()->eq('f.folder_id', 'a.folder_id')
);
)
->where($query->expr()->neq('a.circle_id', $query->createNamedParameter('')));

$queryHelper->limitToInheritedMembers('a', 'circle_id', $federatedUser);
/** @psalm-suppress RedundantCondition */
if (method_exists($queryHelper, 'limitToMemberships')) {
$queryHelper->limitToMemberships('a', 'circle_id', $federatedUser);
} else {
$queryHelper->limitToInheritedMembers('a', 'circle_id', $federatedUser);
}
$this->joinQueryWithFileCache($query, $rootStorageId);

return array_map(fn (array $folder): array => [
Expand Down
31 changes: 31 additions & 0 deletions lib/Migration/Version2000000Date20250128110101.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\GroupFolders\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\Attributes\AddIndex;
use OCP\Migration\Attributes\IndexType;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

#[AddIndex('group_folders_groups', IndexType::INDEX, 'adding index on single circle id for better select')]
class Version2000000Date20250128110101 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

// we recreate the unique key, including circle_id
$table = $schema->getTable('group_folders_groups');
if (!$table->hasIndex('groups_folder_circle')) {
$table->addIndex(['circle_id'], 'groups_folder_circle');
}

return $schema;
}
}
4 changes: 4 additions & 0 deletions tests/stubs/oca_circles_circlesqueryhelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function limitToInheritedMembers(string $alias, string $field, IFederated
{
}

public function limitToMemberships(string $alias, string $field, IFederatedUser $federatedUser): void
{
}


/**
* @param string $field
Expand Down

0 comments on commit 82f40cf

Please sign in to comment.