[TASK] Use stat() instead of filemtime + filesize 56/27256/8
authorMichiel Roos <michiel@maxserv.nl>
Tue, 4 Feb 2014 00:40:39 +0000 (01:40 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Mon, 10 Feb 2014 12:17:30 +0000 (13:17 +0100)
Calling stat() is cheaper than calling filemtime() AND filesize().

Change-Id: I8fc3cb46d934b3c49f6919f7f178e2b232fd62e1
Resolves: #55574
Releases: 6.2
Reviewed-on: https://review.typo3.org/27256
Reviewed-by: Marcin Sągol
Reviewed-by: Karol Lamparski
Reviewed-by: Michał Jankiewicz
Reviewed-by: Stefan Neufeind
Reviewed-by: Michiel Roos
Tested-by: Michiel Roos
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/backend/Classes/Sprite/AbstractSpriteHandler.php
typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
typo3/sysext/core/Classes/Resource/ResourceCompressor.php
typo3/sysext/impexp/Classes/ImportExport.php
typo3/sysext/indexed_search/Classes/Indexer.php

index 0e24de0..c2dcdd9 100644 (file)
@@ -90,7 +90,8 @@ abstract class AbstractSpriteHandler implements \TYPO3\CMS\Backend\Sprite\Sprite
                        // File should be present
                        $allowedCssFilesinTempDir[] = $fileName;
                        // get-Cache Filename
-                       $unique = md5($fileName . filemtime((PATH_site . $file)) . filesize((PATH_site . $file)));
+                       $fileStatus = stat(PATH_site . $file);
+                       $unique = md5($fileName . $fileStatus['mtime'] . $fileStatus['size']);
                        $cacheFile = PATH_site . SpriteManager::$tempPath . $fileName . $unique . '.css';
                        if (!file_exists($cacheFile)) {
                                copy(PATH_site . $file, $cacheFile);
index 1498816..0963f31 100644 (file)
@@ -2329,7 +2329,8 @@ class GraphicalFunctions {
         */
        public function cacheImageDimensions($identifyResult) {
                // Create md5 hash of filemtime and filesize
-               $md5Hash = md5(filemtime($identifyResult[3]) . filesize($identifyResult[3]));
+               $fileStatus = stat($identifyResult[3]);
+               $md5Hash = md5($fileStatus['mtime'] . $fileStatus['size']);
                $result = FALSE;
                if ($md5Hash) {
                        $fieldArray = array(
@@ -2357,7 +2358,8 @@ class GraphicalFunctions {
         */
        public function getCachedImageDimensions($imageFile) {
                // Create md5 hash of filemtime and filesize
-               $md5Hash = md5(filemtime($imageFile) . filesize($imageFile));
+               $fileStatus = stat($imageFile);
+               $md5Hash = md5($fileStatus['mtime'] . $fileStatus['size']);
                $cachedImageDimensions = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('md5hash, md5filename, imagewidth, imageheight', 'cache_imagesizes', 'md5filename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(md5($imageFile), 'cache_imagesizes'));
                $result = FALSE;
                if (is_array($cachedImageDimensions)) {
index 611447d..04852a0 100644 (file)
@@ -306,7 +306,8 @@ class ResourceCompressor {
                        }
                        $filenameAbsolute = GeneralUtility::resolveBackPath($this->rootPath . $filename);
                        if (@file_exists($filenameAbsolute)) {
-                               $unique .= $filenameAbsolute . filemtime($filenameAbsolute) . filesize($filenameAbsolute);
+                               $fileStatus = stat($filenameAbsolute);
+                               $unique .= $filenameAbsolute . $fileStatus['mtime'] . $fileStatus['size'];
                        } else {
                                $unique .= $filenameAbsolute;
                        }
@@ -370,7 +371,8 @@ class ResourceCompressor {
                // generate the unique name of the file
                $filenameAbsolute = GeneralUtility::resolveBackPath($this->rootPath . $this->getFilenameFromMainDir($filename));
                if (@file_exists($filenameAbsolute)) {
-                       $unique = $filenameAbsolute . filemtime($filenameAbsolute) . filesize($filenameAbsolute);
+                       $fileStatus = stat($filenameAbsolute);
+                       $unique = $filenameAbsolute . $fileStatus['mtime'] . $fileStatus['size'];
                } else {
                        $unique = $filenameAbsolute;
                }
@@ -512,7 +514,8 @@ class ResourceCompressor {
                // generate the unique name of the file
                $filenameAbsolute = GeneralUtility::resolveBackPath($this->rootPath . $this->getFilenameFromMainDir($filename));
                if (@file_exists($filenameAbsolute)) {
-                       $unique = $filenameAbsolute . filemtime($filenameAbsolute) . filesize($filenameAbsolute);
+                       $fileStatus = stat($filenameAbsolute);
+                       $unique = $filenameAbsolute . $fileStatus['mtime'] . $fileStatus['size'];
                } else {
                        $unique = $filenameAbsolute;
                }
index 6d5c3fb..ad5f624 100644 (file)
@@ -797,10 +797,11 @@ class ImportExport {
        public function export_addFile($fI, $recordRef = '', $fieldname = '') {
                if (@is_file($fI['ID_absFile'])) {
                        if (filesize($fI['ID_absFile']) < $this->maxFileSize) {
+                               $fileInfo = stat($fI['ID_absFile']);
                                $fileRec = array();
-                               $fileRec['filesize'] = filesize($fI['ID_absFile']);
+                               $fileRec['filesize'] = $fileInfo['size'];
                                $fileRec['filename'] = basename($fI['ID_absFile']);
-                               $fileRec['filemtime'] = filemtime($fI['ID_absFile']);
+                               $fileRec['filemtime'] = $fileInfo['mtime'];
                                //for internal type file_reference
                                $fileRec['relFileRef'] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($fI['ID_absFile']);
                                if ($recordRef) {
@@ -830,10 +831,11 @@ class ImportExport {
                                                $RTEoriginal_absPath = dirname($fI['ID_absFile']) . '/' . $RTEoriginal;
                                                if (@is_file($RTEoriginal_absPath)) {
                                                        $RTEoriginal_ID = md5($RTEoriginal_absPath);
+                                                       $fileInfo = stat($RTEoriginal_absPath);
                                                        $fileRec = array();
-                                                       $fileRec['filesize'] = filesize($RTEoriginal_absPath);
+                                                       $fileRec['filesize'] = $fileInfo['size'];
                                                        $fileRec['filename'] = basename($RTEoriginal_absPath);
-                                                       $fileRec['filemtime'] = filemtime($RTEoriginal_absPath);
+                                                       $fileRec['filemtime'] = $fileInfo['mtime'];
                                                        $fileRec['record_ref'] = '_RTE_COPY_ID:' . $fI['ID'];
                                                        $this->dat['header']['files'][$fI['ID']]['RTE_ORIG_ID'] = $RTEoriginal_ID;
                                                        // Setting this data in the header
@@ -870,10 +872,11 @@ class ImportExport {
                                                                        $prefixedMedias[$k] = '{EXT_RES_ID:' . $EXTres_ID . '}';
                                                                        // Add file to memory if it is not set already:
                                                                        if (!isset($this->dat['header']['files'][$EXTres_ID])) {
+                                                                               $fileInfo = stat($EXTres_absPath);
                                                                                $fileRec = array();
-                                                                               $fileRec['filesize'] = filesize($EXTres_absPath);
+                                                                               $fileRec['filesize'] = $fileInfo['size'];
                                                                                $fileRec['filename'] = basename($EXTres_absPath);
-                                                                               $fileRec['filemtime'] = filemtime($EXTres_absPath);
+                                                                               $fileRec['filemtime'] = $fileInfo['mtime'];
                                                                                $fileRec['record_ref'] = '_EXT_PARENT_:' . $fI['ID'];
                                                                                // Media relative to the HTML file.
                                                                                $fileRec['parentRelFileName'] = $v;
index 45e8fec..38e3fda 100644 (file)
@@ -1128,7 +1128,7 @@ class Indexer {
                // Indexing the document:
                if ($absFile && @is_file($absFile)) {
                        if ($this->external_parsers[$ext]) {
-                               $mtime = filemtime($absFile);
+                               $fileInfo = stat($absFile);
                                $cParts = $this->fileContentParts($ext, $absFile);
                                foreach ($cParts as $cPKey) {
                                        $this->internal_log = array();
@@ -1137,7 +1137,7 @@ class Indexer {
                                        $subinfo = array('key' => $cPKey);
                                        // Setting page range. This is "0" (zero) when no division is made, otherwise a range like "1-3"
                                        $phash_arr = ($this->file_phash_arr = $this->setExtHashes($file, $subinfo));
-                                       $check = $this->checkMtimeTstamp($mtime, $phash_arr['phash']);
+                                       $check = $this->checkMtimeTstamp($fileInfo['mtime'], $phash_arr['phash']);
                                        if ($check > 0 || $force) {
                                                if ($check > 0) {
                                                        $this->log_setTSlogMessage('Indexing needed, reason: ' . $this->reasons[$check], 1);
@@ -1166,10 +1166,8 @@ class Indexer {
                                                                        $this->log_pull();
                                                                        // Submitting page (phash) record
                                                                        $this->log_push('Submitting page', '');
-                                                                       $size = filesize($absFile);
                                                                        // Unfortunately I cannot determine WHEN a file is originally made - so I must return the modification time...
-                                                                       $ctime = filemtime($absFile);
-                                                                       $this->submitFilePage($phash_arr, $file, $subinfo, $ext, $mtime, $ctime, $size, $content_md5h, $contentParts);
+                                                                       $this->submitFilePage($phash_arr, $file, $subinfo, $ext, $fileInfo['mtime'], $fileInfo['ctime'], $fileInfo['size'], $content_md5h, $contentParts);
                                                                        $this->log_pull();
                                                                        // Check words and submit to word list if not there
                                                                        $this->log_push('Check word list and submit words', '');
@@ -1182,7 +1180,7 @@ class Indexer {
                                                                        $this->updateParsetime($phash_arr['phash'], GeneralUtility::milliseconds() - $Pstart);
                                                                } else {
                                                                        // Update the timestamp
-                                                                       $this->updateTstamp($phash_arr['phash'], $mtime);
+                                                                       $this->updateTstamp($phash_arr['phash'], $fileInfo['mtime']);
                                                                        $this->log_setTSlogMessage('Indexing not needed, the contentHash, ' . $content_md5h . ', has not changed. Timestamp updated.');
                                                                }
                                                        } else {