Skip to content

Commit 79db6fe

Browse files
Remove the ENTITY_FQCN_TO_CRUD_FQCN cache entry, which was written but never read
AdminRouteGenerator built and cached a one-to-many entity-to-controllers map on every route generation, but no code reads that cache entry: AdminControllerRegistry derives its own (documented, last-controller-wins) reverse map with array_flip() from the CRUD_FQCN_TO_ENTITY_FQCN entry. Note: this removes the public CacheKey::ENTITY_FQCN_TO_CRUD_FQCN constant.
1 parent 8205de9 commit 79db6fe

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

src/Config/Option/CacheKey.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ final class CacheKey
88
public const ROUTE_ATTRIBUTES_TO_NAME = 'easyadmin.routes.fqcn_to_route';
99
public const DASHBOARD_FQCN_TO_ROUTE = 'easyadmin.routes.controller_fqcn_to_dashboard_route';
1010
public const CRUD_FQCN_TO_ENTITY_FQCN = 'easyadmin.crud.controller_fqcn_to_entity_fqcn';
11-
public const ENTITY_FQCN_TO_CRUD_FQCN = 'easyadmin.crud.entity_fqcn_to_controller_fqcn';
1211
}

src/Router/AdminRouteGenerator.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function generateAll(): RouteCollection
111111
// this dumps all admin routes in a performance-optimized format to later
112112
// find them quickly without having to use Symfony's router service
113113
$this->saveAdminRoutesInCache($adminRoutes);
114-
$this->saveCrudControllersAndEntityFqcnMapInCache($this->crudControllers);
114+
$this->saveCrudControllerToEntityFqcnMapInCache($this->crudControllers);
115115

116116
return $collection;
117117
}
@@ -873,32 +873,21 @@ private function saveAdminRoutesInCache(array $adminRoutes): void
873873
}
874874

875875
// This replaces the ControllerRegistry that existed in previous EasyAdmin versions.
876-
// It stores two maps between CRUD controllers and their associated entity FQCN:
877-
// controller_to_entity: $cache['crud_controller_fqcn'] => 'entity_fqcn'
878-
// entity_to_controller: $cache['entity_fqcn'] => ['crud_controller_fqcn1', 'crud_controller_fqcn2', ...]
876+
// It stores the map between CRUD controllers and their associated entity FQCN:
877+
// $cache['crud_controller_fqcn'] => 'entity_fqcn'
878+
// (AdminControllerRegistry derives the reverse entity-to-controller map from it)
879879
/**
880880
* @param iterable<CrudControllerInterface> $crudControllers
881881
*/
882-
private function saveCrudControllersAndEntityFqcnMapInCache(iterable $crudControllers): void
882+
private function saveCrudControllerToEntityFqcnMapInCache(iterable $crudControllers): void
883883
{
884884
$crudToEntityMap = [];
885-
$entityToCrudMap = [];
886885
foreach ($crudControllers as $crudController) {
887-
$entityFqcn = $crudController::getEntityFqcn();
888-
$crudToEntityMap[$crudController::class] = $entityFqcn;
889-
890-
if (!isset($entityToCrudMap[$entityFqcn])) {
891-
$entityToCrudMap[$entityFqcn] = [];
892-
}
893-
$entityToCrudMap[$entityFqcn][] = $crudController::class;
886+
$crudToEntityMap[$crudController::class] = $crudController::getEntityFqcn();
894887
}
895888

896889
$crudToEntityCacheItem = $this->cache->getItem(CacheKey::CRUD_FQCN_TO_ENTITY_FQCN);
897890
$crudToEntityCacheItem->set($crudToEntityMap);
898891
$this->cache->save($crudToEntityCacheItem);
899-
900-
$entityToCrudCacheItem = $this->cache->getItem(CacheKey::ENTITY_FQCN_TO_CRUD_FQCN);
901-
$entityToCrudCacheItem->set($entityToCrudMap);
902-
$this->cache->save($entityToCrudCacheItem);
903892
}
904893
}

0 commit comments

Comments
 (0)