[BUGFIX] Better caching of TCA for bulk inserts 85/35185/10
authorStephan Großberndt <stephan@grossberndt.de>
Tue, 9 Dec 2014 11:29:54 +0000 (12:29 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 16 Dec 2014 17:13:57 +0000 (18:13 +0100)
Introduces a runtime cache for the TCA types configuration. This
improves performance for bulk inserts since getTCAtypes is called for
each record of each table and the available types during a call do not
change.

Resolves: #63666
Releases: master, 6.2
Change-Id: Ia58352f1bae1e1eb57b87e5db0f1ad84e34ae37e
Reviewed-on: http://review.typo3.org/35185
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index 9b5177e..355e9cf 100644 (file)
@@ -48,6 +48,14 @@ use TYPO3\CMS\Lang\LanguageService;
  */
 class BackendUtility {
 
+       /**
+        * Cache the TCA configuration of tables with their types during runtime
+        *
+        * @var array
+        * @see getTCAtypes()
+        */
+       static protected $tcaTableTypeConfigurationCache = array();
+
        /*******************************************
         *
         * SQL-related, selecting records, searching
@@ -732,6 +740,13 @@ class BackendUtility {
                if ($GLOBALS['TCA'][$table]) {
                        // Get type value:
                        $fieldValue = self::getTCAtypeValue($table, $rec);
+                       $cacheIdentifier = $table . '-type-' . $fieldValue . '-fnk-' . $useFieldNameAsKey;
+
+                       // Fetch from first-level-cache if available
+                       if (isset(self::$tcaTableTypeConfigurationCache[$cacheIdentifier])) {
+                               return self::$tcaTableTypeConfigurationCache[$cacheIdentifier];
+                       }
+
                        // Get typesConf
                        $typesConf = $GLOBALS['TCA'][$table]['types'][$fieldValue];
                        // Get fields list and traverse it
@@ -767,6 +782,10 @@ class BackendUtility {
                        if ($useFieldNameAsKey) {
                                $fieldList = $altFieldList;
                        }
+
+                       // Add to first-level-cache
+                       self::$tcaTableTypeConfigurationCache[$cacheIdentifier] = $fieldList;
+
                        // Return array:
                        return $fieldList;
                }