Skip to content

Commit

Permalink
[TASK] Improve site and document id determination
Browse files Browse the repository at this point in the history
Site and document id determination is improved by using root page
ids if already available, so we can dispense with the unnecessary
use of the RootPageResolver

Resolves: #3709
  • Loading branch information
dkd-friedrich committed Jul 18, 2023
1 parent 7746623 commit 9adf0ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 12 additions & 5 deletions Classes/IndexQueue/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,14 @@ protected function getSolrConnectionsByItem(Item $item): array
$defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPageRecord(), $siteLanguages);
$translationOverlays = $this->getTranslationOverlaysWithConfiguredSite((int)$pageId, $site, $siteLanguages);

$defaultConnection = $this->connectionManager->getConnectionByPageId($rootPageId, $defaultLanguageUid, $item->getMountPointIdentifier() ?? '');
$translationConnections = $this->getConnectionsForIndexableLanguages($translationOverlays);
$mountPointIdentifier = $item->getMountPointIdentifier() ?? '';
if ($mountPointIdentifier !== '') {
$defaultConnection = $this->connectionManager->getConnectionByPageId($rootPageId, $defaultLanguageUid, $mountPointIdentifier);
} else {
$defaultConnection = $this->connectionManager->getConnectionByRootPageId($rootPageId, $defaultLanguageUid);
}

$translationConnections = $this->getConnectionsForIndexableLanguages($translationOverlays, $rootPageId);

if ($defaultLanguageUid == 0) {
$solrConnections[0] = $defaultConnection;
Expand Down Expand Up @@ -588,20 +594,21 @@ protected function getDefaultLanguageUid(Item $item, array $rootPageRecord, arra
/**
* Checks for which languages connections have been configured for translation overlays and returns these connections.
*
* @param array $translationOverlays
* @param int $rootPageId
* @return SolrConnection[]
*
* @throws DBALException
*/
protected function getConnectionsForIndexableLanguages(array $translationOverlays): array
protected function getConnectionsForIndexableLanguages(array $translationOverlays, int $rootPageId): array
{
$connections = [];

foreach ($translationOverlays as $translationOverlay) {
$pageId = $translationOverlay['l10n_parent'];
$languageId = $translationOverlay['sys_language_uid'];

try {
$connection = $this->connectionManager->getConnectionByPageId($pageId, $languageId);
$connection = $this->connectionManager->getConnectionByRootPageId($rootPageId, $languageId);
$connections[$languageId] = $connection;
} catch (NoSolrConnectionFoundException) {
// ignore the exception as we seek only those connections
Expand Down
8 changes: 6 additions & 2 deletions Classes/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace ApacheSolrForTypo3\Solr;

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
Expand Down Expand Up @@ -61,7 +62,10 @@ public static function getPageDocumentId(
$additionalParameters = $mountPointParameter . '/' . $additionalParameters;
}

return self::getDocumentId('pages', $uid, $uid, $additionalParameters);
$rootPageResolver = GeneralUtility::makeInstance(RootPageResolver::class);
$rootPageId = $rootPageResolver->getRootPageId($uid);

return self::getDocumentId('pages', $rootPageId, $uid, $additionalParameters);
}

/**
Expand All @@ -83,7 +87,7 @@ public static function getDocumentId(
string $additionalIdParameters = '',
): string {
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
$site = $siteRepository->getSiteByPageId($rootPageId);
$site = $siteRepository->getSiteByRootPageId($rootPageId);
$siteHash = $site->getSiteHash();

$documentId = $siteHash . '/' . $table . '/' . $uid;
Expand Down

0 comments on commit 9adf0ab

Please sign in to comment.