perf: only load possible results in UserMountCache::getMountForPath#59649
perf: only load possible results in UserMountCache::getMountForPath#59649icewind1991 wants to merge 0 commit intomasterfrom
Conversation
|
/backport to stable33 |
|
/backport to stable32 |
joshtrichards
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Super minor comment tweak:
| // 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 |
There was a problem hiding this comment.
Minor clarity:
| // 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])) { |
There was a problem hiding this comment.
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.
| if (isset($mounts[$searchPath])) { | |
| if (isset($candidateMounts[$searchPath])) { |
| $mounts[$mount->getMountPoint()] = $mount; | ||
| } | ||
| } else { | ||
| $searchPathHashes = array_map(static fn (string $path) => hash('xxh128', $path), $searchPaths); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Perhaps also a test for the negative / NotFoundException path?
860dcce to
be5d980
Compare
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.