Unverified Commit 37fd4a75 authored by alexpott's avatar alexpott

Issue #2924218 by amateescu, Fabianx: Clearing the persistent entity cache...

Issue #2924218 by amateescu, Fabianx: Clearing the persistent entity cache every time we switch between workspaces is super wasteful

(cherry picked from commit bd583a84)
parent 803c6ed9
......@@ -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;
......@@ -47,6 +48,13 @@ class WorkspaceManager implements WorkspaceManagerInterface {
*/
protected $entityTypeManager;
/**
* The entity memory cache service.
*
* @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface
*/
protected $entityMemoryCache;
/**
* The current user.
*
......@@ -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 @@ protected function doSwitchWorkspace(WorkspaceInterface $workspace) {
$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);
}
/**
......
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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment