[BUGFIX] Improve performance iterating local files 76/54576/4
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:16 +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/54576
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php

index 1a8c29d..12418a8 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();