Skip to content

perf: only load possible results in UserMountCache::getMountForPath#59649

Closed
icewind1991 wants to merge 0 commit intomasterfrom
usermountcache-get-by-path-opt
Closed

perf: only load possible results in UserMountCache::getMountForPath#59649
icewind1991 wants to merge 0 commit intomasterfrom
usermountcache-get-by-path-opt

Conversation

@icewind1991
Copy link
Copy Markdown
Member

Extracted from #57760 for easier reviews.

Instead of always loading all mounts for the user and then finding the relevant one for a path. We first collect the possible paths the mountpoint can be at (the path and all it's parents), and then only load the mounts for those paths.

@icewind1991 icewind1991 added this to the Nextcloud 34 milestone Apr 15, 2026
@icewind1991 icewind1991 requested a review from a team as a code owner April 15, 2026 14:01
@icewind1991 icewind1991 requested review from Altahrim, leftybournes, nfebe and salmart-dev and removed request for a team April 15, 2026 14:01
@icewind1991
Copy link
Copy Markdown
Member Author

/backport to stable33

@icewind1991
Copy link
Copy Markdown
Member Author

/backport to stable32

Copy link
Copy Markdown
Member

@joshtrichards joshtrichards left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable optimization. Just some minor comment/suggestions.

// walk up the directory tree until we find a path that has a mountpoint set
// the loop will return if a mountpoint is found or break if none are found
while (true) {
// get all paths that we are interested in, $path and all it's parents
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.

Super minor comment tweak:

Suggested change
// get all paths that we are interested in, $path and all it's parents
// get all paths that we are interested in, $path and all its parents

}
}

// note that $searchPaths is sorted deepest path first
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.

Minor clarity:

Suggested change
// note that $searchPaths is sorted deepest path first
// $searchPaths is ordered deepest-first, so the first hit is the best match.


// note that $searchPaths is sorted deepest path first
foreach ($searchPaths as $searchPath) {
if (isset($mounts[$searchPath])) {
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.

Readability: Maybe use $candidateMounts throughout instead of $mounts to make this final matching loop easier to parse iclearer these are the possible matches, not necessarily all user mounts.

Suggested change
if (isset($mounts[$searchPath])) {
if (isset($candidateMounts[$searchPath])) {

$mounts[$mount->getMountPoint()] = $mount;
}
} else {
$searchPathHashes = array_map(static fn (string $path) => hash('xxh128', $path), $searchPaths);
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.

Readability: Maybe rename the closure arg from $path to $candidatePath to avoid reusing the overarching function parameter's existing parameter name.

$this->assertEquals([null, 1], $mountIds);
}

public function testGetMountForPath(): void {
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.

Perhaps also a test for the negative / NotFoundException path?

@susnux susnux closed this Apr 29, 2026
@susnux susnux force-pushed the usermountcache-get-by-path-opt branch from 860dcce to be5d980 Compare April 29, 2026 20:45
@susnux susnux deleted the usermountcache-get-by-path-opt branch April 29, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants