- π³π±Netherlands tbsiqueira Rotterdam
We also tested patch #6 and it resolved the caching issue, for users that had access to menu the pageload dropped from 6 seconds to 1 second.
When working on improving render caching of menu blocks, I noticed each entry had the canonical path for the current path as part of its cid resulting in many different variants.
After some digging I discovered this is due to the following snippet in "\Drupal\rules\ContextProvider\CurrentPathContext::getRuntimeContexts":
Url::fromRoute('<current>', [], ['absolute' => TRUE])->toString();
This gets called early on in the rendering process causing the "\Drupal\Core\RouteProcessor\RouteProcessorCurrent::processOutbound" (https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21RouteProc...)
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheContexts(['route']);
}
to bubble up the "route" cache tag. When subsequent blocks get rendered they inadvertently create cache redirects (i.e. variants) in the cache_render table based on the route.
A quick fix would be to handle the bubbleable metadata in the CurrentPathContext class. This can be accomplished by adding the `TRUE` flag to the toString function of Url. In doing so the bubbleable metadata will be returned directly instead of pushed up the chain. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/f...
$values = [
'path' => $this->currentPathStack->getPath(),
'url' => Url::fromRoute('<current>', [], ['absolute' => TRUE])->toString(TRUE)->getGeneratedUrl(),
];
$context_definition = new ContextDefinition('current_path', $this->t('Current path'));
$context = new Context($context_definition, $values);
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts(['url.path']);
$context->addCacheableDependency($cacheability);
$result = [
'current_path' => $context,
];
This prevents the 'route' cache tag from bubbling up further. However, I am not sure why we even have the absolute url available in the context? Is this required? Or is the path enough?
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
We also tested patch #6 and it resolved the caching issue, for users that had access to menu the pageload dropped from 6 seconds to 1 second.