[TASK] Remove extbase table column cache 96/49396/3
authorBenni Mack <benni@typo3.org>
Thu, 4 Aug 2016 15:17:04 +0000 (17:17 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 5 Aug 2016 20:07:39 +0000 (22:07 +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/49396
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
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 6408d95..ad01a70 100644 (file)
@@ -205,11 +205,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 5553d01..cf2c8b4 100644 (file)
@@ -67,11 +67,6 @@ class Typo3DbBackend implements BackendInterface, \TYPO3\CMS\Core\SingletonInter
     /**
      * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
      */
-    protected $tableColumnCache;
-
-    /**
-     * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
-     */
     protected $queryCache;
 
     /**
@@ -154,7 +149,6 @@ class Typo3DbBackend implements BackendInterface, \TYPO3\CMS\Core\SingletonInter
      */
     public function initializeObject()
     {
-        $this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns');
         $this->queryCache = $this->cacheManager->getCache('extbase_typo3dbbackend_queries');
     }
 
index e92aecb..b67b418 100644 (file)
@@ -46,16 +46,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;
@@ -69,14 +59,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)
@@ -103,16 +85,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
@@ -753,38 +725,33 @@ 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 (!isset($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 '';
-            }
-            $pageIdStatement = $tableAlias . '.pid IN (' . implode(',', $this->databaseHandle->cleanIntArray($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;
+        return $tableAlias . '.pid IN (' . implode(',', $this->databaseHandle->cleanIntArray($storagePageIds)) . ')';
     }
 
     /**
index d92bb00..b1fa7b1 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Storage;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use Prophecy\Argument;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
 
@@ -393,12 +394,9 @@ 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->getMock(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, array(), array(), '', false);
         $mockDatabaseHandle = $this->prophesize(DatabaseConnection::class);
         $mockDatabaseHandle->cleanIntArray(Argument::cetera())->willReturnArgument(0);
         $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 35e4e2d..ab136eb 100644 (file)
@@ -102,6 +102,8 @@ class SilentConfigurationUpgradeService
         'BE/flexFormXMLincludeDiffBase',
         // #71110
         'BE/maxFileSize',
+        // #77411
+        'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_tablecolumns'
     );
 
     /**