Skip to content
Snippets Groups Projects
Unverified Commit c1ceedb7 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3225034 by bbrala: Simplify ResourceTypeRepository control flow for returning cached data

parent 4441ddc0
No related branches found
No related tags found
No related merge requests found
......@@ -118,24 +118,27 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Ent
*/
public function all() {
$cached = $this->cache->get('jsonapi.resource_types', FALSE);
if ($cached === FALSE) {
$resource_types = [];
foreach ($this->entityTypeManager->getDefinitions() as $entity_type) {
$bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()));
$resource_types = array_reduce($bundles, function ($resource_types, $bundle) use ($entity_type) {
$resource_type = $this->createResourceType($entity_type, (string) $bundle);
return array_merge($resource_types, [
$resource_type->getTypeName() => $resource_type,
]);
}, $resource_types);
}
foreach ($resource_types as $resource_type) {
$relatable_resource_types = $this->calculateRelatableResourceTypes($resource_type, $resource_types);
$resource_type->setRelatableResourceTypes($relatable_resource_types);
}
$this->cache->set('jsonapi.resource_types', $resource_types, Cache::PERMANENT, $this->cacheTags);
if ($cached) {
return $cached->data;
}
return $cached ? $cached->data : $resource_types;
$resource_types = [];
foreach ($this->entityTypeManager->getDefinitions() as $entity_type) {
$bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()));
$resource_types = array_reduce($bundles, function ($resource_types, $bundle) use ($entity_type) {
$resource_type = $this->createResourceType($entity_type, (string) $bundle);
return array_merge($resource_types, [
$resource_type->getTypeName() => $resource_type,
]);
}, $resource_types);
}
foreach ($resource_types as $resource_type) {
$relatable_resource_types = $this->calculateRelatableResourceTypes($resource_type, $resource_types);
$resource_type->setRelatableResourceTypes($relatable_resource_types);
}
$this->cache->set('jsonapi.resource_types', $resource_types, Cache::PERMANENT, $this->cacheTags);
return $resource_types;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment