Skip to content

Commit

Permalink
[#453]: added AppStorage::loadUnchangedByUuid (#453) (#460)
Browse files Browse the repository at this point in the history
Co-authored-by: Arlina Espinoza <[email protected]>
  • Loading branch information
vitalie-cracan and arlina-espinoza authored Sep 29, 2020
1 parent 6461e4f commit ca481c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace Drupal\apigee_edge_teams\ParamConverter;

use Drupal\apigee_edge\Entity\Storage\AppStorage;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
Expand Down Expand Up @@ -84,7 +85,12 @@ public function convert($value, $definition, $name, array $defaults) {
// Load the entity directly from Apigee Edge if needed.
// @see \Drupal\apigee_edge\ParamConverter\ApigeeEdgeLoadUnchangedEntity
if (!empty($defaults['_route_object']->getOption('apigee_edge_load_unchanged_entity'))) {
$entity = $app_storage->loadUnchanged($app_id);
if ($app_storage instanceof AppStorage) {
$entity = $app_storage->loadUnchangedByUuid($app_id);
}
else {
$entity = $app_storage->loadUnchanged($app_id);
}
}
else {
$entity = $app_storage->load($app_id);
Expand Down
24 changes: 24 additions & 0 deletions src/Entity/Storage/AppStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ public function loadUnchanged($id) {
return parent::loadUnchanged($id);
}

/**
* Load app by UUID.
*
* This function is more efficient than loadUnchanged(), because it does not
* need to cover the case when loading is done by App name.
*
* @param string $uuid
* App UUID.
*
* @return \Drupal\apigee_edge\Entity\AppInterface|null
* The unchanged entity, or NULL if the entity cannot be loaded.
*
* @TODO: this method should be also available in the AppStorageInterface, but
* that would be a breaking change, so we can only add that in the next
* major version of the module.
*/
public function loadUnchangedByUuid(string $uuid): ?AppInterface {
// Clear the app controller's cache if it has one.
if ($this->appController instanceof EntityCacheAwareControllerInterface) {
$this->appController->entityCache()->removeEntities([$uuid]);
}
return parent::loadUnchanged($uuid);
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 7 additions & 1 deletion src/ParamConverter/DeveloperAppNameConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace Drupal\apigee_edge\ParamConverter;

use Drupal\apigee_edge\Entity\Storage\AppStorage;
use Drupal\apigee_edge\Exception\DeveloperDoesNotExistException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
Expand Down Expand Up @@ -87,7 +88,12 @@ public function convert($value, $definition, $name, array $defaults) {
// Load the entity directly from Apigee Edge if needed.
// @see \Drupal\apigee_edge\ParamConverter\ApigeeEdgeLoadUnchangedEntity
if (!empty($defaults['_route_object']->getOption('apigee_edge_load_unchanged_entity'))) {
$entity = $app_storage->loadUnchanged($app_id);
if ($app_storage instanceof AppStorage) {
$entity = $app_storage->loadUnchangedByUuid($app_id);
}
else {
$entity = $app_storage->loadUnchanged($app_id);
}
}
else {
$entity = $app_storage->load($app_id);
Expand Down

0 comments on commit ca481c6

Please sign in to comment.