Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Classes/LinkAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Sypets\Brofix\Repository\ContentRepository;
use Sypets\Brofix\Repository\PagesRepository;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
Expand Down Expand Up @@ -58,17 +60,22 @@ class LinkAnalyzer implements LoggerAwareInterface

protected LinkParser $linkParser;

protected FrontendInterface $runtimeCache;

public function __construct(
BrokenLinkRepository $brokenLinkRepository,
ContentRepository $contentRepository,
PagesRepository $pagesRepository,
protected ConnectionPool $connectionPool,
protected Typo3Version $typo3Version
protected Typo3Version $typo3Version,
?CacheManager $cacheManager = null
) {
$this->getLanguageService()->includeLLFile('EXT:brofix/Resources/Private/Language/Module/locallang.xlf');
$this->brokenLinkRepository = $brokenLinkRepository;
$this->contentRepository = $contentRepository;
$this->pagesRepository = $pagesRepository;
$this->runtimeCache = ($cacheManager ?? GeneralUtility::makeInstance(CacheManager::class))
->getCache('runtime');
}

/**
Expand Down Expand Up @@ -684,6 +691,7 @@ public function generateBrokenLinkRecords(ServerRequestInterface $request, array
);

$result = $queryBuilder->executeQuery();
$processed = 0;
while ($row = $result->fetchAssociative()) {
$results = [];

Expand All @@ -700,7 +708,19 @@ public function generateBrokenLinkRecords(ServerRequestInterface $request, array
);

$this->checkLinks($results, $linkTypes);

// Free TYPO3 runtime cache periodically inside the loop. BackendUtility::getRecord(),
// BEgetRootLine() and getPagesTSconfig() (called via isRecordsOnPageShouldBeChecked()
// and downstream) accumulate entries in the TransientMemoryBackend that are never
// freed, which causes OOM in CLI runs over large site trees. Flushing per-chunk is
// not enough on installations where one array_chunk fits the whole site tree.
if ($table !== 'pages' && ++$processed % 1000 === 0) {
$this->runtimeCache->flush();
}
}

// Final flush per chunk to release any remaining entries.
$this->runtimeCache->flush();
}
}

Expand Down