[BUGFIX] Better caching of TCA for bulk inserts 21/35521/2
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 18:48:09 +0000 (19:48 +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/35521
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index 795b464..3084cbc 100644 (file)
@@ -39,6 +39,14 @@ use TYPO3\CMS\Frontend\Page\PageRepository;
  */
 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
@@ -712,6 +720,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
@@ -747,6 +762,10 @@ class BackendUtility {
                        if ($useFieldNameAsKey) {
                                $fieldList = $altFieldList;
                        }
+
+                       // Add to first-level-cache
+                       self::$tcaTableTypeConfigurationCache[$cacheIdentifier] = $fieldList;
+
                        // Return array:
                        return $fieldList;
                }