From ee707f58660cece8f00396738a8150d7e3ded0c1 Mon Sep 17 00:00:00 2001 From: glubsy Date: Tue, 1 Dec 2020 02:16:37 +0000 Subject: [PATCH] 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. --- src/_h5ai/private/php/core/class-context.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/_h5ai/private/php/core/class-context.php b/src/_h5ai/private/php/core/class-context.php index 5484f8f9c..076aca46a 100644 --- a/src/_h5ai/private/php/core/class-context.php +++ b/src/_h5ai/private/php/core/class-context.php @@ -183,7 +183,7 @@ public function get_items($href, $what) { $folder = Item::get($this, $this->to_path($href), $cache); // add content of subfolders - if ($what >= 2 && $folder !== null) { + if ($what >= 3 && $folder !== null) { foreach ($folder->get_content($cache) as $item) { $item->get_content($cache); } @@ -191,11 +191,16 @@ public function get_items($href, $what) { } // add content of this folder and all parent folders - while ($what >= 1 && $folder !== null) { + while ($what >= 2 && $folder !== null) { $folder->get_content($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']); $result = []; foreach ($cache as $p => $item) {