summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-11-22 09:58:54 (GMT)
committerAlex Pott2018-11-22 09:59:01 (GMT)
commit37fd4a75fbbc84cdd94031402f09346651505d7c (patch)
tree5e45590f246c363858286b2767175f1fe629428c
parent803c6ed985abac557020f377caed923b00f4fa83 (diff)
Issue #2924218 by amateescu, Fabianx: Clearing the persistent entity cache every time we switch between workspaces is super wasteful
(cherry picked from commit bd583a846c0c5e5be3cc72b07106785191834acb)
-rw-r--r--core/modules/workspaces/src/WorkspaceManager.php22
-rw-r--r--core/modules/workspaces/workspaces.services.yml2
2 files changed, 18 insertions, 6 deletions
diff --git a/core/modules/workspaces/src/WorkspaceManager.php b/core/modules/workspaces/src/WorkspaceManager.php
index 0fe39f5..837edef 100644
--- a/core/modules/workspaces/src/WorkspaceManager.php
+++ b/core/modules/workspaces/src/WorkspaceManager.php
@@ -2,6 +2,7 @@
namespace Drupal\workspaces;
+use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityTypeInterface;
@@ -48,6 +49,13 @@ class WorkspaceManager implements WorkspaceManagerInterface {
protected $entityTypeManager;
/**
+ * The entity memory cache service.
+ *
+ * @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface
+ */
+ protected $entityMemoryCache;
+
+ /**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
@@ -96,6 +104,8 @@ class WorkspaceManager implements WorkspaceManagerInterface {
* The request stack.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
+ * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $entity_memory_cache
+ * The entity memory cache service.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user.
* @param \Drupal\Core\State\StateInterface $state
@@ -107,9 +117,10 @@ class WorkspaceManager implements WorkspaceManagerInterface {
* @param array $negotiator_ids
* The workspace negotiator service IDs.
*/
- public function __construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $current_user, StateInterface $state, LoggerInterface $logger, ClassResolverInterface $class_resolver, array $negotiator_ids) {
+ public function __construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, MemoryCacheInterface $entity_memory_cache, AccountProxyInterface $current_user, StateInterface $state, LoggerInterface $logger, ClassResolverInterface $class_resolver, array $negotiator_ids) {
$this->requestStack = $request_stack;
$this->entityTypeManager = $entity_type_manager;
+ $this->entityMemoryCache = $entity_memory_cache;
$this->currentUser = $current_user;
$this->state = $state;
$this->logger = $logger;
@@ -204,10 +215,11 @@ class WorkspaceManager implements WorkspaceManagerInterface {
$this->activeWorkspace = $workspace;
- $supported_entity_types = $this->getSupportedEntityTypes();
- foreach ($supported_entity_types as $supported_entity_type) {
- $this->entityTypeManager->getStorage($supported_entity_type->id())->resetCache();
- }
+ // Clear the static entity cache for the supported entity types.
+ $cache_tags_to_invalidate = array_map(function ($entity_type_id) {
+ return 'entity.memory_cache:' . $entity_type_id;
+ }, array_keys($this->getSupportedEntityTypes()));
+ $this->entityMemoryCache->invalidateTags($cache_tags_to_invalidate);
}
/**
diff --git a/core/modules/workspaces/workspaces.services.yml b/core/modules/workspaces/workspaces.services.yml
index a238473..ab9e8bf 100644
--- a/core/modules/workspaces/workspaces.services.yml
+++ b/core/modules/workspaces/workspaces.services.yml
@@ -1,7 +1,7 @@
services:
workspaces.manager:
class: Drupal\workspaces\WorkspaceManager
- arguments: ['@request_stack', '@entity_type.manager', '@current_user', '@state', '@logger.channel.workspaces', '@class_resolver']
+ arguments: ['@request_stack', '@entity_type.manager', '@entity.memory_cache', '@current_user', '@state', '@logger.channel.workspaces', '@class_resolver']
tags:
- { name: service_id_collector, tag: workspace_negotiator }
workspaces.operation_factory: