Skip to content

Commit 22f3a19

Browse files
committed
optimize
1 parent cb0765e commit 22f3a19

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Traits/HasWallets.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ trait HasWallets
2626
*/
2727
private $_wallets = [];
2828

29+
/**
30+
* @var bool
31+
*/
32+
private $_loadedWallets = false;
33+
2934
/**
3035
* Get wallet by slug
3136
*
@@ -43,11 +48,8 @@ trait HasWallets
4348
*/
4449
public function getWallet(string $slug): ?WalletModel
4550
{
46-
if (\array_key_exists($slug, $this->_wallets)) {
47-
return $this->_wallets[$slug];
48-
}
49-
50-
if ($this->relationLoaded('wallets')) {
51+
if (!$this->_loadedWallets && $this->relationLoaded('wallets')) {
52+
$this->_loadedWallets = true;
5153
$wallets = $this->getRelation('wallets');
5254
foreach ($wallets as $wallet) {
5355
$this->_wallets[$wallet->slug] = $wallet;

0 commit comments

Comments
 (0)