[BUGFIX] Flush frontend cache when AI label metadata changes - #35
[BUGFIX] Flush frontend cache when AI label metadata changes#35achimfritz wants to merge 1 commit into
Conversation
6ba6a19 to
698b3c3
Compare
698b3c3 to
4e35684
Compare
o-ba
left a comment
There was a problem hiding this comment.
The bug is real and I even reproduced it. But most of the diff is IMOunnecessary. TYPO3’s DataHandler already flushes the page-cache tag sys_file_metadata_<uid> on every write to that table, with no feature flag involved. What’s missing is only the tag on the page-cache entry. On a fresh v14 install the bug doesn’t occur at all, because core’s frontend.cache.autoTagging is on there.
So I see following options:
-
Only configuration, zero code: Set
frontend.cache.autoTagging = trueand document it. Core then tags every page cache entry withsys_file_metadata_<uid>fromResourceStorage::getPublicUrl()and DataHandler flushes it. The flag is on for instances installed on v13.3+, manual for upgraded ones. -
Keep one extension-side tag and drop the rest:
Classes/Service/CacheHelper.php, keepaddCacheTag(), deleteinvalidate(),getServerRequestInterface()and the CacheManager dependency, rename to something that says what it does (FrontendCacheTaggeror similar), and take the request as an argument:
public function addCacheTag(FileReference $fileReference, ?ServerRequestInterface $request): void
{
// Unconditional, also for unflagged files: a file that gets flagged later must
// invalidate the pages that already rendered it.
$metadataUid = $fileReference->hasProperty('metadata_uid')
? (int)$fileReference->getProperty('metadata_uid')
: 0;
$collector = $request?->getAttribute('frontend.cache.collector');
if ($metadataUid <= 0 || !$collector instanceof CacheDataCollector) {
return;
}
// Core's own tag name, the one ResourceStorage::getPublicUrl() emits under
// frontend.cache.autoTagging, and the one DataHandler already flushes on every
// sys_file_metadata write. So nothing here has to flush anything itself.
$collector->addCacheTags(new CacheTag('sys_file_metadata_' . $metadataUid));
}
FileMetadataViewHelper:
$this->cacheTagger->addCacheTag(
$fileReference,
$this->renderingContext->hasAttribute(ServerRequestInterface::class)
? $this->renderingContext->getAttribute(ServerRequestInterface::class)
: null
);
What Option 2 doesn’t cover, and the README should say: the tag is only added where a template calls <ailabel:fileMetadata>. Only Option 1 covers those, which is why the feature flag is the primary fix and the tag the fallback.
No description provided.