From 2930603eced227451e2710932781d7fa064118c2 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Tue, 11 Dec 2018 11:53:02 +0100 Subject: [PATCH] Avoid double caching of OgMembership entities. Fixes #445 --- src/MembershipManager.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) 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]); } /**