/** @var ReferenceIndex $referenceIndex */
$referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class);
+ $referenceIndex->enableRuntimeCache();
$referenceIndex->updateIndex($isTestOnly, $isSilent);
}
}
if (@is_file($copyDestName)) {
/** @var ReferenceIndex $sysRefObj */
$sysRefObj = GeneralUtility::makeInstance(ReferenceIndex::class);
+ $sysRefObj->enableRuntimeCache();
$error = $sysRefObj->setReferenceValue($rteFileRecord['hash'], PathUtility::stripPathSitePrefix($copyDestName), false, true);
if ($error) {
$this->newlog(ReferenceIndex::class . '::setReferenceValue(): ' . $error, 1);
// Use reference index object to find files in fields:
/** @var ReferenceIndex $refIndexObj */
$refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class);
+ $refIndexObj->enableRuntimeCache();
$files = $refIndexObj->getRelations_procFiles($dataValue, $dsArr['TCEforms']['config'], $PA['uid']);
// Traverse files and delete them if the field is a regular file field (and not a file_reference field)
if (is_array($files) && $dsArr['TCEforms']['config']['internal_type'] === 'file') {
if (BackendUtility::isTableWorkspaceEnabled($table)) {
$refIndexObj->setWorkspaceId($this->BE_USER->workspace);
}
+ $refIndexObj->enableRuntimeCache();
$refIndexObj->updateRefIndexTable($table, $id);
}
*/
protected $runtimeCache = null;
+ /**
+ * Enables $runtimeCache and $recordCache
+ * @var bool
+ */
+ protected $useRuntimeCache = false;
+
/**
* Constructor
*/
// Fetch tableRelationFields and save them in cache if not there yet
$cacheId = static::$cachePrefixTableRelationFields . $tableName;
- if (!$this->runtimeCache->has($cacheId)) {
+ if (!$this->useRuntimeCache || !$this->runtimeCache->has($cacheId)) {
$tableRelationFields = $this->fetchTableRelationFields($tableName);
$this->runtimeCache->set($cacheId, $tableRelationFields);
} else {
* - Relations may change during indexing, which is why only the origin record is cached and all relations are re-process even when repeating
* indexing of the same origin record
*
+ * Please note that the cache is disabled by default but can be enabled using $this->enableRuntimeCaches()
+ * due to possible side-effects while handling references that were changed during one single
+ * request.
+ *
* @param string $tableName
* @param int $uid
* @return array|false
protected function getRecordRawCached(string $tableName, int $uid)
{
$recordCacheId = $tableName . ':' . $uid;
- if (!isset($this->recordCache[$recordCacheId])) {
+ if (!$this->useRuntimeCache || !isset($this->recordCache[$recordCacheId])) {
// Fetch fields of the table which might contain relations
$cacheId = static::$cachePrefixTableRelationFields . $tableName;
- if (!$this->runtimeCache->has($cacheId)) {
+ if (!$this->useRuntimeCache || !$this->runtimeCache->has($cacheId)) {
$tableRelationFields = $this->fetchTableRelationFields($tableName);
- $this->runtimeCache->set($cacheId, $tableRelationFields);
+ if ($this->useRuntimeCache) {
+ $this->runtimeCache->set($cacheId, $tableRelationFields);
+ }
} else {
$tableRelationFields = $this->runtimeCache->get($cacheId);
}
return true;
}
+ /**
+ * Enables the runtime-based caches
+ * Could lead to side effects, depending if the reference index instance is run multiple times
+ * while records would be changed.
+ */
+ public function enableRuntimeCache()
+ {
+ $this->useRuntimeCache = true;
+ }
+
+ /**
+ * Disables the runtime-based cache
+ */
+ public function disableRuntimeCache()
+ {
+ $this->useRuntimeCache = false;
+ }
+
/**
* Returns the current BE user.
*
if (BackendUtility::isTableWorkspaceEnabled($table)) {
$refIndexObj->setWorkspaceId($this->getWorkspaceId());
}
+ $refIndexObj->enableRuntimeCache();
$statisticsArray = $refIndexObj->updateRefIndexTable($table, $id);
}
return $statisticsArray;
{
/** @var $refIndexObj ReferenceIndex */
$refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class);
+ $refIndexObj->enableRuntimeCache();
$refIndexObj->updateRefIndexTable($this->table, $id);
}
{
$this->configurationManager = $configurationManager;
$this->referenceIndex = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
+ $this->referenceIndex->enableRuntimeCache();
$this->aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->deletedEntities = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->changedEntities = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->dat['header']['pid_lookup'][$row['pid']][$table][$row['uid']] = 1;
// Initialize reference index object:
$refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class);
+ $refIndexObj->enableRuntimeCache();
// Yes to workspace overlays for exporting....
$refIndexObj->WSOL = true;
$relations = $refIndexObj->getRelations($table, $row);
$testOnly = (bool)GeneralUtility::_GP('_check');
// Call the functionality
$refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class);
+ $refIndexObj->enableRuntimeCache();
list(, $bodyContent) = $refIndexObj->updateIndex($testOnly);
$this->view->assign('content', str_replace('##LF##', '<br />', $bodyContent));
}