Skip to content

Commit

Permalink
Update Setting.php
Browse files Browse the repository at this point in the history
Clear resolved facade instance to fix race condition issue while fetching settings on very high loads.
  • Loading branch information
janiskelemen authored Feb 14, 2023
1 parent e6791f7 commit 620c290
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace JanisKelemen\Setting;

use Illuminate\Support\Facades\Facade;
use Illuminate\Contracts\Cache\Factory as CacheContract;
use JanisKelemen\Setting\Contracts\SettingStorageContract;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -31,6 +32,8 @@ public function all()
return is_array($item) && isset($item['default_value']) ? $item['default_value'] : $item;
});
$all = $this->storage->whereLocale(null)->get()->pluck('value', 'key');

Facade::clearResolvedInstance('Setting');

return collect($all)->union($configSettings);
}
Expand Down Expand Up @@ -108,6 +111,8 @@ public function get($key, $default_value = null)
if (is_null($setting)) {
$setting = is_null($default_value) ? $this->default($key) : $default_value;
}

Facade::clearResolvedInstance('Setting');

return $setting;
}
Expand Down Expand Up @@ -166,6 +171,8 @@ public function mergeValues($mainkey, $value)
}

$setting = $dot->all();

Facade::clearResolvedInstance('Setting');

return $setting;
}
Expand All @@ -186,6 +193,8 @@ public function set($key, $value)
$this->setByKey($key, $value);
}
$this->resetLang();

Facade::clearResolvedInstance('Setting');
}

/**
Expand Down

0 comments on commit 620c290

Please sign in to comment.