Skip to content

fix(api): fix performance issue on PROPFIND api#4676

Open
tpelingan wants to merge 1 commit into
nextcloud:masterfrom
tpelingan:master
Open

fix(api): fix performance issue on PROPFIND api#4676
tpelingan wants to merge 1 commit into
nextcloud:masterfrom
tpelingan:master

Conversation

@tpelingan
Copy link
Copy Markdown

This fixes #4095

Problem
After upgrading groupfolders from v19 to v20, PROPFIND /remote.php/dav/files/{user}/ became significantly slower for instances with many groupfolders (e.g., 600+ folders: 4s → 18s).

Root cause: Commit 2637d7d ("remove assumptions that all groupfolders share a storage id") introduced per-folder node resolution in FolderStorageManager::getBaseStorageForFolderRootJail(). Each call to parentFolder->get((string)$folderId) triggers a separate SELECT on oc_filecache. With N groupfolders, this creates an N+1 query problem — N extra DB queries per PROPFIND request.

@tpelingan
Copy link
Copy Markdown
Author

Hi @provokateurin can you help check from your end if this is good enough? This was able to reduce the query time of PROPFIND from 208 seconds -> 46 seconds. And on another instance from 944 sec to 116 sec

Comment thread lib/Mount/FolderStorageManager.php Outdated
Comment thread lib/Mount/FolderStorageManager.php Outdated
@tpelingan tpelingan force-pushed the master branch 2 times, most recently from f920420 to 257439c Compare May 19, 2026 05:36
Copy link
Copy Markdown
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

I get the feeling that you don't understand and test the code changes. This PR is not working in its current state and the optimization you're trying to apply will break, too.

Comment thread lib/Mount/FolderStorageManager.php
Comment thread lib/Mount/FolderStorageManager.php Outdated
Comment on lines +227 to +228
// a separate SELECT on oc_filecache via parentFolder->get(folderId).
$basePath = $parentFolder->getInternalPath();
Copy link
Copy Markdown
Member

@provokateurin provokateurin May 19, 2026

Choose a reason for hiding this comment

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

Yes, but this is needed in order to create the folder if it is missing, so you can't remove it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

interesting. what if we do a query only if the folder is missing?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

and how do you suggest that we fix the N+1 query issue introduced here on version 20?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But you can't know if the folder exists or not without doing a query.

A solution might be to create these subfolders when the groupfolder is created, but I'm not even sure if that would make it work.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I see. Can we not make the GET PROPFIND API be purely read only? I'm a bit surprised that these operations need to happen. Is there a specific reason or can we maybe remove the folder creation logic?

This fixes nextcloud#4095

Signed-off-by: tpelingan <theodoro.pelingan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance regression 19 vs. 20

3 participants