use Drupal\Core\Condition\ConditionPluginCollection;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
use Drupal\pathauto\PathautoPatternInterface;
$context_handler = \Drupal::service('context.handler');
$conditions = $this->getSelectionConditions();
foreach ($conditions as $condition) {
+
+ // As the context object is kept and only the value is switched out,
+ // it can over time grow to a huge number of cache contexts. Reset it
+ // if there are 100 cache tags to prevent cache tag merging getting too
+ // slow.
+ foreach ($condition->getContextDefinitions() as $name => $context_definition) {
+ if (count($condition->getContext($name)->getCacheTags()) > 100) {
+ $condition->setContext($name, new Context($context_definition));
+ }
+ }
+
if ($condition instanceof ContextAwarePluginInterface) {
try {
$context_handler->applyContextMapping($condition, $contexts);