From 3a292415e8702941d17eab0f6f49ef5fcf05780a Mon Sep 17 00:00:00 2001 From: Daniel Abplanalp Date: Fri, 27 Sep 2019 09:53:35 +0200 Subject: [PATCH] speed up multi-domains/sites installation with many slug conflicts --- Classes/Utility/SlugHelper.php | 105 ++++++++++++++++++++++++++++++++ Classes/Utility/SlugUtility.php | 2 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 Classes/Utility/SlugHelper.php diff --git a/Classes/Utility/SlugHelper.php b/Classes/Utility/SlugHelper.php new file mode 100644 index 0000000..1ad8ba2 --- /dev/null +++ b/Classes/Utility/SlugHelper.php @@ -0,0 +1,105 @@ +resolveNodeAggregateIdentifier(); + $recordId = $state->getSubject()->getIdentifier(); + $languageId = $state->getContext()->getLanguageId(); + + if (!MathUtility::canBeInterpretedAsInteger($pageId)) { + // If this is a new page, we use the parent page to resolve the site + $pageId = $state->getNode()->getIdentifier(); + } + $pageId = (int)$pageId; + + if ($pageId < 0) { + $pageId = $this->resolveLivePageId($recordId); + } + $queryBuilder = $this->createPreparedQueryBuilder(); + $this->applySlugConstraint($queryBuilder, $slug); + $this->applyRecordConstraint($queryBuilder, $recordId); + $this->applyLanguageConstraint($queryBuilder, $languageId); + $this->applyWorkspaceConstraint($queryBuilder); + $statement = $queryBuilder->execute(); + + $records = $this->resolveVersionOverlays( + $statement->fetchAll() + ); + if (count($records) === 0) { + return true; + } + //return true; + + // The installation contains at least ONE other record with the same slug + // Now find out if it is the same root page ID + $siteMatcher = GeneralUtility::makeInstance(SiteMatcher::class); + // Changes: it is just too slow for multi domain sites with many slug conflicts - but uncommenting is also not the best idea [Daniel Abplanalp 2019-09-27] + //$siteMatcher->refresh(); + $siteOfCurrentRecord = $siteMatcher->matchByPageId($pageId); + foreach ($records as $record) { + try { + $recordState = RecordStateFactory::forName($this->tableName)->fromArray($record); + $siteOfExistingRecord = $siteMatcher->matchByPageId( + (int)$recordState->resolveNodeAggregateIdentifier() + ); + } catch (SiteNotFoundException $exception) { + // In case not site is found, the record is not + // organized in any site or pseudo-site + continue; + } + if ($siteOfExistingRecord->getRootPageId() === $siteOfCurrentRecord->getRootPageId()) { + return false; + } + } + + // Otherwise, everything is still fine + return true; + } + + + +} diff --git a/Classes/Utility/SlugUtility.php b/Classes/Utility/SlugUtility.php index 0905b72..41c8d96 100644 --- a/Classes/Utility/SlugUtility.php +++ b/Classes/Utility/SlugUtility.php @@ -6,7 +6,7 @@ use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\DataHandling\Model\RecordStateFactory; -use TYPO3\CMS\Core\DataHandling\SlugHelper; +//use TYPO3\CMS\Core\DataHandling\SlugHelper; use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction; use TYPO3\CMS\Core\Type\Bitmask\Permission; use TYPO3\CMS\Core\Cache\CacheManager;