[!!!][TASK] Drop extbase query cache 09/49409/9
authorBenni Mack <benni@typo3.org>
Wed, 10 Aug 2016 18:10:08 +0000 (20:10 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 11 Aug 2016 19:57:38 +0000 (21:57 +0200)
The database is having a query cache to exactly take care of that,
no need to cache a preparsed query (done in PHP) to be stored in
a different DB table by default to optimize speed.

Any interface related method and properties throw a deprecation
notice but will have no effect anymore.

The interface method has been removed, being compatible with
all existing older versions of the interface.

Resolves: #77460
Releases: master
Change-Id: I11e9d6c367a32fad2fa77ecd85172fc242ca1fe9
Reviewed-on: https://review.typo3.org/49409
Tested-by: Bamboo TYPO3com <info@typo3.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/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-77460-ExtbaseQueryCacheRemoved.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Generic/QueryFactory.php
typo3/sysext/extbase/Classes/Persistence/Generic/QuerySettingsInterface.php
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Classes/Persistence/Generic/Typo3QuerySettings.php
typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php

index 5c9c33d..98b8fad 100644 (file)
@@ -190,11 +190,6 @@ return array(
                     ),
                     'groups' => array('system')
                 ),
-                'extbase_typo3dbbackend_queries' => array(
-                    'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
-                    'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
-                    'groups' => array('system'),
-                ),
                 'extbase_datamapfactory_datamap' => 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/Breaking-77460-ExtbaseQueryCacheRemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-77460-ExtbaseQueryCacheRemoved.rst
new file mode 100644 (file)
index 0000000..db52cae
--- /dev/null
@@ -0,0 +1,32 @@
+==============================================
+Breaking: #77460 - Extbase query cache removed
+==============================================
+
+Description
+===========
+
+The PHP-based query cache functionality within the Extbase persistence layer has been removed.
+
+The following public methods within the Extbase persistence layer have been removed:
+ * Typo3DbBackend->quoteTextValueCallback()
+ * Typo3DbBackend->initializeObject()
+ * Typo3DbBackend->injectCacheManager()
+ * Interface definition in QuerySettingsInterface->getUseQueryCache
+
+
+Impact
+======
+
+The according cache configuration set via ``$TYPO3_CONF_VARS[SYS][cache][cacheConfigurations][extbase_typo3dbbackend_queries]`` has no effect anymore.
+
+
+Affected Installations
+======================
+
+Any installation effectively relying on the query cache via a third party extension or explicitly deactivating the query cache of extbase.
+
+
+Migration
+=========
+
+Remove the according lines and migrate to Doctrine.
\ No newline at end of file
index 92dd84e..2946da8 100644 (file)
@@ -77,9 +77,6 @@ class QueryFactory implements QueryFactoryInterface, \TYPO3\CMS\Core\SingletonIn
 
         $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
         $querySettings->setStoragePageIds(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']));
-        if ($querySettings instanceof Typo3QuerySettings) {
-            $querySettings->useQueryCache($frameworkConfiguration['persistence']['useQueryCache']);
-        }
         $query->setQuerySettings($querySettings);
         return $query;
     }
index e6349fd..641abb7 100644 (file)
@@ -162,9 +162,4 @@ interface QuerySettingsInterface
      * @return bool
      */
     public function getIncludeDeleted();
-
-    /**
-     * @return bool
-     */
-    public function getUseQueryCache();
 }
index e48d753..c802e1c 100644 (file)
@@ -72,16 +72,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     protected $cacheService;
 
     /**
-     * @var \TYPO3\CMS\Core\Cache\CacheManager
-     */
-    protected $cacheManager;
-
-    /**
-     * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
-     */
-    protected $queryCache;
-
-    /**
      * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
      */
     protected $environmentService;
@@ -92,13 +82,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     protected $queryParser;
 
     /**
-     * A first level cache for queries during runtime
-     *
-     * @var array
-     */
-    protected $queryRuntimeCache = array();
-
-    /**
      * @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper
      */
     public function injectDataMapper(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper)
@@ -123,14 +106,6 @@ class Typo3DbBackend implements BackendInterface, 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)
@@ -156,16 +131,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     }
 
     /**
-     * Lifecycle method
-     *
-     * @return void
-     */
-    public function initializeObject()
-    {
-        $this->queryCache = $this->cacheManager->getCache('extbase_typo3dbbackend_queries');
-    }
-
-    /**
      * Adds a row to the storage
      *
      * @param string $tableName The database table name
@@ -370,7 +335,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
         if ($statement instanceof Qom\Statement) {
             $rows = $this->getObjectDataByRawQuery($statement);
         } else {
-            list($statementParts) = $this->getStatementParts($query);
+            $statementParts = $this->getStatementParts($query);
             $rows = $this->getRowsFromDatabase($statementParts);
         }
 
@@ -475,7 +440,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException('Could not execute count on queries with a constraint of type TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Statement', 1256661045);
         }
 
-        list($statementParts) = $this->getStatementParts($query);
+        $statementParts = $this->getStatementParts($query);
 
         $fields = '*';
         if (isset($statementParts['keywords']['distinct'])) {
@@ -502,35 +467,16 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
     }
 
     /**
-     * Looks for the query in cache or builds it up otherwise
+     * Build the query statement parts as SQL
      *
      * @param QueryInterface $query
-     * @param bool $resolveParameterPlaceholders whether to resolve the parameters or leave the placeholders
      * @return array
      * @throws \RuntimeException
      */
-    protected function getStatementParts($query, $resolveParameterPlaceholders = true)
+    protected function getStatementParts($query)
     {
-        /**
-         * The queryParser will preparse the query to get the query's hash and parameters.
-         * If the hash is found in the cache and useQueryCaching is enabled, extbase will
-         * then take the string representation from cache and build a prepared query with
-         * the parameters found.
-         *
-         * Otherwise extbase will parse the complete query, build the string representation
-         * and run a usual query.
-         */
-        list($queryHash, $parameters) = $this->queryParser->preparseQuery($query);
-
-        if ($query->getQuerySettings()->getUseQueryCache()) {
-            $statementParts = $this->getQueryCacheEntry($queryHash);
-            if ($queryHash && !$statementParts) {
-                $statementParts = $this->queryParser->parseQuery($query);
-                $this->setQueryCacheEntry($queryHash, $statementParts);
-            }
-        } else {
-            $statementParts = $this->queryParser->parseQuery($query);
-        }
+        list($_, $parameters) = $this->queryParser->preparseQuery($query);
+        $statementParts = $this->queryParser->parseQuery($query);
 
         if (!$statementParts) {
             throw new \RuntimeException('Your query could not be built.', 1394453197);
@@ -542,11 +488,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
         $statementParts['limit'] = ((int)$query->getLimit() ?: null);
         $statementParts['offset'] = ((int)$query->getOffset() ?: null);
 
-        if ($resolveParameterPlaceholders === true) {
-            $statementParts = $this->resolveParameterPlaceholders($statementParts, $parameters);
-        }
-
-        return array($statementParts, $parameters);
+        return $this->resolveParameterPlaceholders($statementParts, $parameters);
     }
 
     /**
@@ -925,31 +867,4 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             $this->cacheService->getPageIdStack()->push($pageIdToClear);
         }
     }
-
-    /**
-     * Finds and returns a variable value from the query cache.
-     *
-     * @param string $entryIdentifier Identifier of the cache entry to fetch
-     * @return mixed The value
-     */
-    protected function getQueryCacheEntry($entryIdentifier)
-    {
-        if (!isset($this->queryRuntimeCache[$entryIdentifier])) {
-            $this->queryRuntimeCache[$entryIdentifier] = $this->queryCache->get($entryIdentifier);
-        }
-        return $this->queryRuntimeCache[$entryIdentifier];
-    }
-
-    /**
-     * Saves the value of a PHP variable in the query cache.
-     *
-     * @param string $entryIdentifier An identifier used for this cache entry
-     * @param mixed $variable The query to cache
-     * @return void
-     */
-    protected function setQueryCacheEntry($entryIdentifier, $variable)
-    {
-        $this->queryRuntimeCache[$entryIdentifier] = $variable;
-        $this->queryCache->set($entryIdentifier, $variable, array(), 0);
-    }
 }
index 69497f9..50ceb9b 100644 (file)
@@ -102,6 +102,7 @@ class Typo3QuerySettings implements QuerySettingsInterface
      * Flag whether the query should be cached using the caching framework
      *
      * @var bool
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
      */
     protected $useQueryCache = true;
 
@@ -362,19 +363,23 @@ class Typo3QuerySettings implements QuerySettingsInterface
 
     /**
      * @param bool $useQueryCache
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
      * @return QuerySettingsInterface
      */
     public function useQueryCache($useQueryCache)
     {
+        GeneralUtility::logDeprecatedFunction();
         $this->useQueryCache = (bool)$useQueryCache;
         return $this;
     }
 
     /**
      * @return bool
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
      */
     public function getUseQueryCache()
     {
+        GeneralUtility::logDeprecatedFunction();
         return $this->useQueryCache;
     }
 }
index 7e1e876..a909189 100644 (file)
@@ -82,7 +82,9 @@ class SilentConfigurationUpgradeService
         // #75625
         'SYS/clearCacheSystem',
         // #77411
-        'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_tablecolumns'
+        'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_tablecolumns',
+        // #77460
+        'SYS/caching/cacheConfigurations/extbase_typo3dbbackend_queries'
     ];
 
     public function __construct(ConfigurationManager $configurationManager = null)