Skip to content

Conversation

@Rello
Copy link

@Rello Rello commented Jan 22, 2026

Motivation

  • Avoid full-table scans and high-memory iterations when checking mountpoints by using a targeted lookup instead of iterating all folders.
  • Reduce global table reads for applicable/group mappings by scoping queries to only requested folder IDs.

Description

  • Replace loop-based mountpoint existence check in lib/Controller/FolderController.php with a call to FolderManager::mountPointExists() to perform a single targeted query.
  • Add mountPointExists() to lib/Folder/FolderManager.php to check for a mount point using a single-row query.
  • Introduce getApplicableForFolders() and getApplicableForFolder() and getFolderMappingsForFolders() in lib/Folder/FolderManager.php to fetch applicable groups/circles and manage mappings for a specified list of folder IDs.
  • Update getAllFoldersWithSize(), getAllFoldersForUserWithSize(), getFolder(), getGroups(), and getCircles() to use the new scoped helpers instead of loading all applicable/mapping rows, including safe early-return when the folder ID list is empty.

Background

  • customer performance issue with >50k group folders
  • required for NC31

@Rello Rello changed the title Optimize group folder queries fix: Optimize group folder queries Jan 22, 2026
$applicableMap[$id] = [];
}

if (!$row['circle_id']) {
Copy link
Member

Choose a reason for hiding this comment

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

This check is very ugly, at least invert it

Comment on lines +573 to +580
$query->select('folder_id')
->from('group_folders')
->where($query->expr()->eq('mount_point', $query->createNamedParameter($mountPoint)))
->setMaxResults(1);

$result = $query->executeQuery();
$exists = $result->fetchOne() !== false;
$result->closeCursor();
Copy link
Member

Choose a reason for hiding this comment

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

Selecting the count of rows might allow the DB to operate more efficiently.

Rello and others added 2 commits January 23, 2026 08:11
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com>
Signed-off-by: Rello <Rello@users.noreply.github.com>
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com>
Signed-off-by: Rello <Rello@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants