Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / pathauto / src / Entity / PathautoPattern.php
index 3a1d23eaa46857609c82c20eac132804a0072e8e..e297f2a703ac45a6b24f764216e752274fadb349 100644 (file)
@@ -6,6 +6,7 @@ use Drupal\Component\Plugin\Exception\ContextException;
 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;
@@ -345,6 +346,17 @@ class PathautoPattern extends ConfigEntityBase implements PathautoPatternInterfa
       $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);