1
0
Fork 0
mirror of https://github.com/lrsjng/h5ai synced 2025-12-15 13:22:49 +01:00

Fix overhead when loading directory

* This avoids loading content of parent directories, only adding the
requested directory.
* This drastically reduces the amount of fstat system calls, and avoid
superfluous items in the response array, i.e. files from directories we
don't necessarily care about.
* This should reduce timeouts when loading directories with large numbers
of files.
This commit is contained in:
glubsy 2020-12-01 02:16:37 +00:00
parent d81d8a9298
commit ee707f5866

View file

@ -183,7 +183,7 @@ class Context {
$folder = Item::get($this, $this->to_path($href), $cache); $folder = Item::get($this, $this->to_path($href), $cache);
// add content of subfolders // add content of subfolders
if ($what >= 2 && $folder !== null) { if ($what >= 3 && $folder !== null) {
foreach ($folder->get_content($cache) as $item) { foreach ($folder->get_content($cache) as $item) {
$item->get_content($cache); $item->get_content($cache);
} }
@ -191,11 +191,16 @@ class Context {
} }
// add content of this folder and all parent folders // add content of this folder and all parent folders
while ($what >= 1 && $folder !== null) { while ($what >= 2 && $folder !== null) {
$folder->get_content($cache); $folder->get_content($cache);
$folder = $folder->get_parent($cache); $folder = $folder->get_parent($cache);
} }
// only add the requested folder (less fstat overhead)
if ($what == 1 && $folder !== null) {
$folder->get_content($cache);
}
uasort($cache, ['Item', 'cmp']); uasort($cache, ['Item', 'cmp']);
$result = []; $result = [];
foreach ($cache as $p => $item) { foreach ($cache as $p => $item) {