diff --git a/src/MembershipManager.php b/src/MembershipManager.php index 7677d35f4..6e04cc2c8 100644 --- a/src/MembershipManager.php +++ b/src/MembershipManager.php @@ -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]); } /**