[FEATURE] Introduce signal in loadBaseTca 33/29433/4
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 12 Apr 2014 17:09:30 +0000 (19:09 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 14 Apr 2014 12:19:32 +0000 (14:19 +0200)
To improve performance in backend context, final
TCA should be cached in contrast to only parts of it.

To be able to cache the complete TCA, we need to introduce a signal
after building the cached TCA from files.

#57862 describes further steps, which are not in scope of this change.

This is a completely non breaking change, it only
adds new API which extension authors can also
use to benefit from the resulting performance gain.

Resolves: #57863
Documentation: #57895
Releases: 6.2
Change-Id: I1174b68b59f2ebc5b8c0c227ac13102366c2136a
Reviewed-on: https://review.typo3.org/29433
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php

index d88cade..35d74de 100644 (file)
@@ -75,7 +75,7 @@ class ExtensionManagementUtility {
        /**
         * Getter for the cache manager
         *
-        * @return \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
+        * @return \TYPO3\CMS\Core\Cache\CacheManager
         */
        static protected function getCacheManager() {
                if (static::$cacheManager === NULL) {
@@ -84,6 +84,23 @@ class ExtensionManagementUtility {
                return static::$cacheManager;
        }
 
+       /**
+        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        */
+       static protected $signalSlotDispatcher;
+
+       /**
+        * Getter for the signal slot dispatcher
+        *
+        * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        */
+       static protected function getSignalSlotDispatcher() {
+               if (static::$signalSlotDispatcher === NULL) {
+                       static::$signalSlotDispatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
+               }
+               return static::$signalSlotDispatcher;
+       }
+
        /**************************************
         *
         * PATHS and other evaluation
@@ -1582,6 +1599,7 @@ tt_content.' . $key . $prefix . ' {
                                $GLOBALS['TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
                        } else {
                                static::buildBaseTcaFromSingleFiles();
+                               static::emitTcaIsBeingBuiltSignal($GLOBALS['TCA']);
                                static::createBaseTcaCacheFile();
                        }
                } else {
@@ -1623,6 +1641,21 @@ tt_content.' . $key . $prefix . ' {
        }
 
        /**
+        * Emits the signal and uses the result of slots for the final TCA
+        * This means, that *all* slots *must* return the complete TCA to
+        * be effective. If a slot calls methods that manipulate the global array,
+        * it needs to return the global array in the end. To be future proof,
+        * a slot should manipulate the signal argument only and return it
+        * after manipulation.
+        *
+        * @param array $tca
+        */
+       static protected function emitTcaIsBeingBuiltSignal(array $tca) {
+               list($tca) = static::getSignalSlotDispatcher()->dispatch(__CLASS__, 'tcaIsBeingBuilt', array($tca));
+               $GLOBALS['TCA'] = $tca;
+       }
+
+       /**
         * Cache base $GLOBALS['TCA'] to cache file to require the whole thing in one
         * file for next access instead of cycling through all extensions again.
         *
index 368425e..08b9d38 100644 (file)
@@ -122,6 +122,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                                '    return parent::getExtTablesCacheIdentifier();' .
                                '  }' .
                                '  public static function buildBaseTcaFromSingleFiles() {' .
+                               '    $GLOBALS[\'TCA\'] = array();' .
+                               '  }' .
+                               '  public static function emitTcaIsBeingBuiltSignal(array $tca) {' .
                                '  }' .
                                '}'
                        );