Skip to content

Commit ca481c6

Browse files
[#453]: added AppStorage::loadUnchangedByUuid (#453) (#460)
Co-authored-by: Arlina Espinoza <[email protected]>
1 parent 6461e4f commit ca481c6

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

modules/apigee_edge_teams/src/ParamConverter/TeamAppNameConverter.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace Drupal\apigee_edge_teams\ParamConverter;
2222

23+
use Drupal\apigee_edge\Entity\Storage\AppStorage;
2324
use Drupal\Core\Entity\EntityTypeManagerInterface;
2425
use Drupal\Core\Logger\LoggerChannelInterface;
2526
use Drupal\Core\ParamConverter\ParamConverterInterface;
@@ -84,7 +85,12 @@ public function convert($value, $definition, $name, array $defaults) {
8485
// Load the entity directly from Apigee Edge if needed.
8586
// @see \Drupal\apigee_edge\ParamConverter\ApigeeEdgeLoadUnchangedEntity
8687
if (!empty($defaults['_route_object']->getOption('apigee_edge_load_unchanged_entity'))) {
87-
$entity = $app_storage->loadUnchanged($app_id);
88+
if ($app_storage instanceof AppStorage) {
89+
$entity = $app_storage->loadUnchangedByUuid($app_id);
90+
}
91+
else {
92+
$entity = $app_storage->loadUnchanged($app_id);
93+
}
8894
}
8995
else {
9096
$entity = $app_storage->load($app_id);

src/Entity/Storage/AppStorage.php

+24
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ public function loadUnchanged($id) {
9494
return parent::loadUnchanged($id);
9595
}
9696

97+
/**
98+
* Load app by UUID.
99+
*
100+
* This function is more efficient than loadUnchanged(), because it does not
101+
* need to cover the case when loading is done by App name.
102+
*
103+
* @param string $uuid
104+
* App UUID.
105+
*
106+
* @return \Drupal\apigee_edge\Entity\AppInterface|null
107+
* The unchanged entity, or NULL if the entity cannot be loaded.
108+
*
109+
* @TODO: this method should be also available in the AppStorageInterface, but
110+
* that would be a breaking change, so we can only add that in the next
111+
* major version of the module.
112+
*/
113+
public function loadUnchangedByUuid(string $uuid): ?AppInterface {
114+
// Clear the app controller's cache if it has one.
115+
if ($this->appController instanceof EntityCacheAwareControllerInterface) {
116+
$this->appController->entityCache()->removeEntities([$uuid]);
117+
}
118+
return parent::loadUnchanged($uuid);
119+
}
120+
97121
/**
98122
* {@inheritdoc}
99123
*/

src/ParamConverter/DeveloperAppNameConverter.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace Drupal\apigee_edge\ParamConverter;
2222

23+
use Drupal\apigee_edge\Entity\Storage\AppStorage;
2324
use Drupal\apigee_edge\Exception\DeveloperDoesNotExistException;
2425
use Drupal\Core\Entity\EntityTypeManagerInterface;
2526
use Drupal\Core\Logger\LoggerChannelInterface;
@@ -87,7 +88,12 @@ public function convert($value, $definition, $name, array $defaults) {
8788
// Load the entity directly from Apigee Edge if needed.
8889
// @see \Drupal\apigee_edge\ParamConverter\ApigeeEdgeLoadUnchangedEntity
8990
if (!empty($defaults['_route_object']->getOption('apigee_edge_load_unchanged_entity'))) {
90-
$entity = $app_storage->loadUnchanged($app_id);
91+
if ($app_storage instanceof AppStorage) {
92+
$entity = $app_storage->loadUnchangedByUuid($app_id);
93+
}
94+
else {
95+
$entity = $app_storage->loadUnchanged($app_id);
96+
}
9197
}
9298
else {
9399
$entity = $app_storage->load($app_id);

0 commit comments

Comments
 (0)