Fixed bug #12232: [Performance] md5_file() to check if a file has been changed is...
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 18 Jan 2011 21:32:37 +0000 (21:32 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 18 Jan 2011 21:32:37 +0000 (21:32 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10126 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_stdgraphic.php

index 1529838..44d1f7e 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
 
 2011-01-18  Christian Kuhn  <lolli@schwarzbu.ch>
 
+       * Fixed bug #12232: [Performance] md5_file() to check if a file has been changed is very expensive (Thanks to André Stösel and Vladimir Podkovanov)
        * Fixed bug #16685: [Performance] Not using table index while deleting cached imagesize (Thanks to Vladimir Podkovanov)
        * Fixed bug #16462: Link field for images is too short to provide links for every image (Thanks to Jo Hasenau)
 
index a3c77c6..ea7509d 100644 (file)
@@ -2356,11 +2356,12 @@ class t3lib_stdGraphic {
         * @author      Michael Stucki <michael@typo3.org> / Robert Lemke <rl@robertlemke.de>
         */
        function cacheImageDimensions($identifyResult) {
-               global $TYPO3_DB;
-                       // Create a md5 hash of the filename
-               $md5Hash = md5_file($identifyResult[3]);
+                       // Create md5 hash of filemtime and filesize
+               $md5Hash = md5(filemtime($identifyResult[3]) . filesize($identifyResult[3]));
+
+               $result = FALSE;
                if ($md5Hash) {
-                       $fieldArr = array(
+                       $fieldArray = array(
                                'md5hash' => $md5Hash,
                                'md5filename' => md5($identifyResult[3]),
                                'tstamp' => $GLOBALS['EXEC_TIME'],
@@ -2368,12 +2369,18 @@ class t3lib_stdGraphic {
                                'imagewidth' => $identifyResult[0],
                                'imageheight' => $identifyResult[1],
                        );
-                       $TYPO3_DB->exec_INSERTquery('cache_imagesizes', $fieldArr);
-                       if (!$err = $TYPO3_DB->sql_error()) {
-                               return TRUE;
+
+                       $GLOBALS['TYPO3_DB']->exec_INSERTquery(
+                               'cache_imagesizes',
+                               $fieldArray
+                       );
+
+                       if (!$err = $GLOBALS['TYPO3_DB']->sql_error()) {
+                               $result = TRUE;
                        }
                }
-               return FALSE;
+
+               return $result;
        }
 
        /**
@@ -2385,10 +2392,8 @@ class t3lib_stdGraphic {
         * @author      Robert Lemke <rl@robertlemke.de>
         */
        function getCachedImageDimensions($imageFile) {
-                       // Create a md5 hash of the filename
-               $md5Hash = md5_file($imageFile);
-
-               preg_match('/([^\.]*)$/', $imageFile, $imageExtension);
+                       // Create md5 hash of filemtime and filesize
+               $md5Hash = md5(filemtime($imageFile) . filesize($imageFile));
 
                $cachedImageDimensions = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
                        'md5hash, md5filename, imagewidth, imageheight',
@@ -2405,6 +2410,7 @@ class t3lib_stdGraphic {
                                        'md5filename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($cachedImageDimensions['md5filename'], 'cache_imagesizes')
                                );
                        } else {
+                               preg_match('/([^\.]*)$/', $imageFile, $imageExtension);
                                $result = array(
                                        (int)$cachedImageDimensions['imagewidth'],
                                        (int)$cachedImageDimensions['imageheight'],