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

Commit b54a74e

Browse files
authored
Merge pull request #446 from Gizra/avoid-double-caching
Avoid double caching of OgMembership entities.
2 parents b37caed + 65c95a8 commit b54a74e

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/MembershipManager.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,20 @@ public function getMemberships(AccountInterface $user, array $states = [OgMember
9797
];
9898
$identifier = implode(':', $identifier);
9999

100-
// Return cached result if it exists.
101-
if (isset($this->cache[$identifier])) {
102-
return $this->cache[$identifier];
103-
}
104-
105-
$query = $this->entityTypeManager
106-
->getStorage('og_membership')
107-
->getQuery()
108-
->condition('uid', $user->id())
109-
->condition('state', $states, 'IN');
100+
// Use cached result if it exists.
101+
if (!isset($this->cache[$identifier])) {
102+
$query = $this->entityTypeManager
103+
->getStorage('og_membership')
104+
->getQuery()
105+
->condition('uid', $user->id())
106+
->condition('state', $states, 'IN');
110107

111-
$results = $query->execute();
108+
$this->cache[$identifier] = $query->execute();
109+
}
112110

113-
/** @var \Drupal\og\Entity\OgMembership[] $memberships */
114-
$this->cache[$identifier] = $this->entityTypeManager
111+
return $this->entityTypeManager
115112
->getStorage('og_membership')
116-
->loadMultiple($results);
117-
118-
return $this->cache[$identifier];
113+
->loadMultiple($this->cache[$identifier]);
119114
}
120115

121116
/**

0 commit comments

Comments
 (0)