Commit e1fbc3b3 authored by Benni Mack's avatar Benni Mack Committed by Stefan Neufeind
Browse files

[TASK] Speed up page ID resolving in Extbase BE

Extbase does some simple calls to determine the
page ID of the current request, and does not cache it.

This costs some mySQL calls, which are unneeded
once the current page ID is found. The page ID is
now stored in the ConfigurationManager to retrieve
with a simple runtime cache.

Resolves: #55566
Resolves: #57125
Releases: 6.2
Change-Id: Id5fe4a25591c77ce8a81cefa018a04e803ba7e8a
Reviewed-on: https://review.typo3.org/27243
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
parent 5132dcdd
......@@ -45,6 +45,12 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
*/
protected $typoScriptSetupCache = array();
/**
* stores the current page ID
* @var integer
*/
protected $currentPageId;
/**
* Returns TypoScript Setup array from current Environment.
*
......@@ -127,22 +133,56 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
* @return integer current page id. If no page is selected current root page id is returned
*/
protected function getCurrentPageId() {
$pageId = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
if ($pageId > 0) {
return $pageId;
if ($this->currentPageId !== NULL) {
return $this->currentPageId;
}
// get current site root
$rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
if (count($rootPages) > 0) {
return $rootPages[0]['uid'];
$this->currentPageId = $this->getCurrentPageIdFromGetPostData() ?: $this->getCurrentPageIdFromCurrentSiteRoot();
$this->currentPageId = $this->currentPageId ?: $this->getCurrentPageIdFromRootTemplate();
$this->currentPageId = $this->currentPageId ?: self::DEFAULT_BACKEND_STORAGE_PID;
return $this->currentPageId;
}
/**
* Gets the current page ID from the GET/POST data.
*
* @return int the page UID, will be 0 if none has been set
*/
protected function getCurrentPageIdFromGetPostData() {
return (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
}
/**
* Gets the current page ID from the first site root in tree.
*
* @return int the page UID, will be 0 if none has been set
*/
protected function getCurrentPageIdFromCurrentSiteRoot() {
$rootPage = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting'
);
if (empty($rootPage)) {
return 0;
}
// get root template
$rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
if (count($rootTemplates) > 0) {
return $rootTemplates[0]['pid'];
return (int)$rootPage['uid'];
}
/**
* Gets the current page ID from the first created root template.
*
* @return int the page UID, will be 0 if none has been set
*/
protected function getCurrentPageIdFromRootTemplate() {
$rootTemplate = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate'
);
if (empty($rootTemplate)) {
return 0;
}
// fallback
return self::DEFAULT_BACKEND_STORAGE_PID;
return (int)$rootTemplate['pid'];
}
/**
......
......@@ -78,10 +78,10 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
* @test
*/
public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound() {
$GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetRows')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')->will($this->returnValue(array()));
$GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetRows')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')->will($this->returnValue(array(
$GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(array()));
$GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue(
array('pid' => 123)
)));
));
$expectedResult = 123;
$actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
$this->assertEquals($expectedResult, $actualResult);
......@@ -91,9 +91,9 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
* @test
*/
public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet() {
$GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')->will($this->returnValue(array(
$GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(
array('uid' => 321)
)));
));
$expectedResult = 321;
$actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
$this->assertEquals($expectedResult, $actualResult);
......@@ -103,8 +103,8 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
* @test
*/
public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound() {
$GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetRows')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')->will($this->returnValue(array()));
$GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetRows')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')->will($this->returnValue(array()));
$GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(array()));
$GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue(array()));
$expectedResult = \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager::DEFAULT_BACKEND_STORAGE_PID;
$actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
$this->assertEquals($expectedResult, $actualResult);
......
......@@ -235,7 +235,8 @@ CREATE TABLE sys_template (
PRIMARY KEY (uid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY parent (pid,deleted,hidden,sorting)
KEY parent (pid,deleted,hidden,sorting),
KEY roottemplate (deleted,hidden,root)
);
#
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment