[BUGFIX] Improve performance iterating local files 27/54627/2
authorStephan Großberndt <stephan@grossberndt.de>
Tue, 7 Nov 2017 08:44:24 +0000 (09:44 +0100)
committerFrans Saris <franssaris@gmail.com>
Mon, 13 Nov 2017 08:47:54 +0000 (09:47 +0100)
Improve performance iterating local files by avoiding multiple calls to
SplFileInfo.

Releases: master, 8.7
Resolves: #82936
Change-Id: I54b347ad4734d9083b67c7840ff3ab228c07f4bc
Reviewed-on: https://review.typo3.org/54627
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php

index 56b0654..84783aa 100644 (file)
@@ -535,21 +535,26 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
         while ($iterator->valid()) {
             /** @var $entry \SplFileInfo */
             $entry = $iterator->current();
-            // skip non-files/non-folders, and empty entries
-            if ((!$entry->isFile() && !$entry->isDir()) || $entry->getFilename() == '' ||
-                ($entry->isFile() && !$includeFiles) || ($entry->isDir() && !$includeDirs)) {
+            $isFile = $entry->isFile();
+            $isDirectory = $isFile ? false : $entry->isDir();
+            if (
+                (!$isFile && !$isDirectory) // skip non-files/non-folders
+                || ($isFile && !$includeFiles) // skip files if they are excluded
+                || ($isDirectory && !$includeDirs) // skip directories if they are excluded
+                || $entry->getFilename() === '' // skip empty entries
+            ) {
                 $iterator->next();
                 continue;
             }
             $entryIdentifier = '/' . substr($entry->getPathname(), $pathLength);
             $entryName = PathUtility::basename($entryIdentifier);
-            if ($entry->isDir()) {
+            if ($isDirectory) {
                 $entryIdentifier .= '/';
             }
             $entryArray = [
                 'identifier' => $entryIdentifier,
                 'name' => $entryName,
-                'type' => $entry->isDir() ? 'dir' : 'file'
+                'type' => $isDirectory ? 'dir' : 'file'
             ];
             $directoryEntries[$entryIdentifier] = $entryArray;
             $iterator->next();