[TASK] Remove extbase table column cache 85/49385/8
authorBenni Mack <benni@typo3.org>
Thu, 4 Aug 2016 15:17:04 +0000 (17:17 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 5 Aug 2016 14:05:11 +0000 (16:05 +0200)
The extbase table column cache "extbase_typo3dbbackend_tablecolumns"
stores all DB fields of all DB tables to detect if the TCA table contains
a field named "pid".

However, if a DB table has a TCA definition but no PID, then it fails
at so many places. No need to execute a admin_get_fields call on every
method call.
(Which caches this information - ironically - in the database by default)

The cache can be removed without substitution as the superfluous
check on the DB field "pid" is removed.

Resolves: #77411
Releases: master, 7.6
Change-Id: Ib4dca4e5f895f0e4334c26482423b833dcb773ca
Reviewed-on: https://review.typo3.org/49385
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Important-77411-RemovedExtbaseTableColumnCache.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbQueryParserTest.php
typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php

index 748fb89..ca89633 100644 (file)
@@ -190,11 +190,6 @@ return array(
                     ),
                     'groups' => array('system')
                 ),
-                'extbase_typo3dbbackend_tablecolumns' => array(
-                    'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
-                    'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
-                    'groups' => array('system'),
-                ),
                 'extbase_typo3dbbackend_queries' => array(
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
                     'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-77411-RemovedExtbaseTableColumnCache.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-77411-RemovedExtbaseTableColumnCache.rst
new file mode 100644 (file)
index 0000000..78ae2c1
--- /dev/null
@@ -0,0 +1,12 @@
+======================================================
+Important: #77411 - Removed extbase table column cache
+======================================================
+
+Description
+===========
+
+The extbase table column cache "extbase_typo3dbbackend_tablecolumns",
+which was used to store all database fields of all database tables,
+was removed.
+
+The associated configuration variable ``$TYPO3_CONF_VARS[SYS][caching][cacheConfigurations][extbase_typo3dbbackend_tablecolumns]`` can be removed.
\ No newline at end of file
index da0364b..dd439ef 100644 (file)
@@ -79,11 +79,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     /**
      * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
      */
-    protected $tableColumnCache;
-
-    /**
-     * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
-     */
     protected $queryCache;
 
     /**
@@ -167,7 +162,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
      */
     public function initializeObject()
     {
-        $this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns');
         $this->queryCache = $this->cacheManager->getCache('extbase_typo3dbbackend_queries');
     }
 
index 7a8ef03..03562c9 100644 (file)
@@ -48,16 +48,6 @@ class Typo3DbQueryParser implements \TYPO3\CMS\Core\SingletonInterface
     protected $pageRepository;
 
     /**
-     * @var \TYPO3\CMS\Core\Cache\CacheManager
-     */
-    protected $cacheManager;
-
-    /**
-     * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
-     */
-    protected $tableColumnCache;
-
-    /**
      * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
      */
     protected $environmentService;
@@ -71,14 +61,6 @@ class Typo3DbQueryParser implements \TYPO3\CMS\Core\SingletonInterface
     }
 
     /**
-     * @param \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
-     */
-    public function injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
-    {
-        $this->cacheManager = $cacheManager;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
      */
     public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
@@ -105,16 +87,6 @@ class Typo3DbQueryParser implements \TYPO3\CMS\Core\SingletonInterface
     }
 
     /**
-     * Lifecycle method
-     *
-     * @return void
-     */
-    public function initializeObject()
-    {
-        $this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns');
-    }
-
-    /**
      * Preparses the query and returns the query's hash and the parameters
      *
      * @param QueryInterface $query The query
@@ -755,39 +727,35 @@ class Typo3DbQueryParser implements \TYPO3\CMS\Core\SingletonInterface
      */
     protected function getPageIdStatement($tableName, $tableAlias, array $storagePageIds)
     {
-        $pageIdStatement = '';
-        $tableColumns = $this->tableColumnCache->get($tableName);
-        if ($tableColumns === false) {
-            $tableColumns = $this->databaseHandle->admin_get_fields($tableName);
-            $this->tableColumnCache->set($tableName, $tableColumns);
-        }
-        if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $tableColumns)) {
-            $rootLevel = (int)$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel'];
-            switch ($rootLevel) {
-                // Only in pid 0
-                case 1:
+        if (!is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
+            return '';
+        }
+
+        $rootLevel = (int)$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel'];
+        switch ($rootLevel) {
+            // Only in pid 0
+            case 1:
+                return $tableAlias . '.pid = 0';
+            // Pid 0 and pagetree
+            case -1:
+                if (empty($storagePageIds)) {
                     return $tableAlias . '.pid = 0';
-                // Pid 0 and pagetree
-                case -1:
-                    if (empty($storagePageIds)) {
-                        return $tableAlias . '.pid = 0';
-                    }
-                    $storagePageIds[] = 0;
-                    break;
-                // Only pagetree or not set
-                case 0:
-                    if (empty($storagePageIds)) {
-                        throw new InconsistentQuerySettingsException('Missing storage page ids.', 1365779762);
-                    }
-                    break;
-                // Invalid configuration
-                default:
-                    return '';
-            }
-            $storagePageIds = array_map('intval', $storagePageIds);
-            $pageIdStatement = $tableAlias . '.pid IN (' . implode(',', $storagePageIds) . ')';
+                }
+                $storagePageIds[] = 0;
+                break;
+            // Only pagetree or not set
+            case 0:
+                if (empty($storagePageIds)) {
+                    throw new InconsistentQuerySettingsException('Missing storage page ids.', 1365779762);
+                }
+                break;
+            // Invalid configuration
+            default:
+                return '';
         }
-        return $pageIdStatement;
+        $storagePageIds = array_map('intval', $storagePageIds);
+
+        return $tableAlias . '.pid IN (' . implode(',', $storagePageIds) . ')';
     }
 
     /**
index fda0576..bd34d20 100644 (file)
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Storage;
 use Prophecy\Argument;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -487,11 +486,6 @@ class Typo3DbQueryParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
             'rootLevel' => $rootLevel
         );
         $mockTypo3DbQueryParser = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class, array('dummy'), array(), '', false);
-        $mockFrontendVariableCache = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class);
-        $mockDatabaseHandle = $this->prophesize(DatabaseConnection::class);
-        $mockTypo3DbQueryParser->_set('databaseHandle', $mockDatabaseHandle->reveal());
-        $mockTypo3DbQueryParser->_set('tableColumnCache', $mockFrontendVariableCache);
-        $mockFrontendVariableCache->expects($this->once())->method('get')->will($this->returnValue(array('pid' => '42')));
         $sql = $mockTypo3DbQueryParser->_callRef('getPageIdStatement', $table, $table, $storagePageIds);
 
         $this->assertSame($expectedSql, $sql);
index 4f7a64c..7e1e876 100644 (file)
@@ -81,6 +81,8 @@ class SilentConfigurationUpgradeService
         'BE/compactFlexFormXML',
         // #75625
         'SYS/clearCacheSystem',
+        // #77411
+        'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_tablecolumns'
     ];
 
     public function __construct(ConfigurationManager $configurationManager = null)