Skip to content

Commit c1e294a

Browse files
committed
trim and perf
Trimming suffix and prefix, performance improvement #30
1 parent c5408a9 commit c1e294a

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

Classes/Core/Functions.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ public static function prepareforOutput($path,$lConf) {
200200
$path = (string)$lConf->urlprefix.$path;
201201
}
202202
if (self::excludeInclude($path,$lConf->urlsuffix)) {
203-
$path .= (string)$lConf->urlsuffix;
203+
$suffix = (string)$lConf->urlsuffix;
204+
$path .= trim($suffix);
204205
}
205206
return $path;
206207
}
@@ -452,10 +453,12 @@ public static function specCharsToASCII($title) {
452453

453454
public static function prepareLinkForCache($path,$lConf) {
454455
if (!empty($lConf->cache->prefix)) {
455-
$path = ($lConf->cache->prefix).$path;
456+
$prefix = (string)$lConf->cache->prefix;
457+
$path = trim($prefix).$path;
456458
}
457459
if (!empty($lConf->cache->suffix)) {
458-
$path .= ($lConf->cache->suffix);
460+
$suffix = (string)$lConf->cache->suffix;
461+
$path .= trim($suffix);
459462
}
460463
if (!empty($lConf->removetrailingslash) && $lConf->removetrailingslash==1) {
461464
$temppath = self::removeSlash($path);

Classes/Core/Translate.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ private function removeUriParts($uri) {
7676
private function removeFixes($uri) {
7777
$temp = explode('?',$uri);
7878
if (!empty(self::$conf->urlsuffix)) {
79-
$temp[0] = preg_replace('~'.Functions::addregexpslashes((string)self::$conf->urlsuffix).'$~','',$temp[0]);
79+
$suffix = (string)self::$conf->urlsuffix;
80+
$suffix = trim($suffix);
81+
$temp[0] = preg_replace('~'.Functions::addregexpslashes($suffix).'$~','',$temp[0]);
8082
}
8183
if (!empty(self::$conf->urlprefix)) {
82-
$temp[0] = preg_replace('~^'.Functions::addregexpslashes((string)self::$conf->urlprefix).'~','',$temp[0]);
84+
$prefix = (string)self::$conf->urlprefix;
85+
$prefix = trim($prefix);
86+
$temp[0] = preg_replace('~^'.Functions::addregexpslashes($prefix).'~','',$temp[0]);
8387
}
8488
$uri = implode('?',$temp);
8589
return $uri;

Classes/Integration/CoolUri.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ public static function findDomainGroup($domain)
368368

369369
public static function getDomain($id)
370370
{
371+
static $domains = array();
372+
if (isset($domains[$id])) {
373+
return $domains[$id];
374+
}
375+
371376
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Getting domain for ' . $id, 'CoolUri');
372377
if ($GLOBALS['TSFE']->showHiddenPage || self::isBEUserLoggedIn()) {
373378
$enable = ' AND pages.deleted=0';
@@ -388,6 +393,7 @@ public static function getDomain($id)
388393
if ($page['domainName'] && !$page['redirectTo']) {
389394
$resDom = preg_replace('~^.*://(.*)/?$~', '\\1', preg_replace('~/$~', '', $page['domainName']));
390395
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Resolved domain: ' . $resDom, 'CoolUri');
396+
$domains[$id] = $resDom;
391397
return $resDom;
392398
}
393399

@@ -399,6 +405,7 @@ public static function getDomain($id)
399405

400406
if ($page['is_siteroot'] == 1 || $count['num'] > 0) {
401407
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Domain missing for ID ' . $id . ', using HTTP_HOST ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'), 'CoolUri');
408+
$domains[$id] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
402409
return \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
403410
}
404411

@@ -407,6 +414,7 @@ public static function getDomain($id)
407414
--$max;
408415
}
409416
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Domain not found, using HTTP_HOST ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'), 'CoolUri', 2);
417+
$domains[$id] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
410418
return \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
411419
}
412420

0 commit comments

Comments
 (0)