Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Avoid double caching of OgMembership entities.
Browse files Browse the repository at this point in the history
Fixes #445
  • Loading branch information
pfrenssen committed Dec 11, 2018
1 parent 556eb67 commit 2930603
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/MembershipManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,22 @@ public function getMemberships(AccountInterface $user, array $states = [OgMember
$identifier = implode(':', $identifier);

// Return cached result if it exists.
if (isset($this->cache[$identifier])) {
return $this->cache[$identifier];
}
if (!isset($this->cache[$identifier])) {
$query = $this->entityTypeManager
->getStorage('og_membership')
->getQuery()
->condition('uid', $user->id());

$query = $this->entityTypeManager
->getStorage('og_membership')
->getQuery()
->condition('uid', $user->id());
if ($states) {
$query->condition('state', $states, 'IN');
}

if ($states) {
$query->condition('state', $states, 'IN');
$this->cache[$identifier] = $query->execute();
}

$results = $query->execute();

/** @var \Drupal\og\Entity\OgMembership[] $memberships */
$this->cache[$identifier] = $this->entityTypeManager
return $this->entityTypeManager
->getStorage('og_membership')
->loadMultiple($results);

return $this->cache[$identifier];
->loadMultiple($this->cache[$identifier]);
}

/**
Expand Down

0 comments on commit 2930603

Please sign in to comment.