diff --git a/system/libs/pot/OTS_Groups_List.php b/system/libs/pot/OTS_Groups_List.php index 664ef9bc..7791027f 100644 --- a/system/libs/pot/OTS_Groups_List.php +++ b/system/libs/pot/OTS_Groups_List.php @@ -47,8 +47,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable return; } - $groups = new Groups(); - foreach($groups->getGroups() as $id => $info) { + foreach(Groups::get() as $id => $info) { $this->groups[$id] = new OTS_Group($info); } } diff --git a/system/src/Server/Groups.php b/system/src/Server/Groups.php index 5e393a35..7d489f6a 100644 --- a/system/src/Server/Groups.php +++ b/system/src/Server/Groups.php @@ -8,22 +8,22 @@ class Groups { private static array $groups = []; - public function __construct() { - self::$groups = Cache::remember('groups', 10 * 60, function () { - if (file_exists(config('server_path') . 'config/groups.toml')) { - $groups = new TOML\Groups(); - } - else { - $groups = new XML\Groups(); - } + public static function get() { + if (count(self::$groups) == 0) { + self::$groups = Cache::remember('groups', 10 * 60, function () { + if (file_exists(config('server_path') . TOML\Groups::FILE)) { + $groups = new TOML\Groups(); + } + else { + $groups = new XML\Groups(); + } - $groups->load(); + $groups->load(); - return $groups->getGroups(); - }); - } + return $groups->getGroups(); + }); + } - public static function getGroups(): array { return self::$groups; } } diff --git a/system/src/Server/Mounts.php b/system/src/Server/Mounts.php index ae6e6d24..c072cdc9 100644 --- a/system/src/Server/Mounts.php +++ b/system/src/Server/Mounts.php @@ -6,19 +6,25 @@ use MyAAC\Cache\Cache; class Mounts { + private static array $mounts = []; + public static function get() { - return Cache::remember('mounts', 10 * 60, function () { - if (file_exists(config('server_path') . TOML\Mounts::FILE)) { - $mounts = new TOML\Mounts(); - } - else { - $mounts = new XML\Mounts(); - } + if (count(self::$mounts) == 0) { + self::$mounts = Cache::remember('mounts', 10 * 60, function () { + if (file_exists(config('server_path') . TOML\Mounts::FILE)) { + $mounts = new TOML\Mounts(); + } + else { + $mounts = new XML\Mounts(); + } - $mounts->load(); + $mounts->load(); - return $mounts->get(); - }); + return $mounts->get(); + }); + } + + return self::$mounts; } } diff --git a/system/src/Server/Outfits.php b/system/src/Server/Outfits.php index fbcc7068..5ca42299 100644 --- a/system/src/Server/Outfits.php +++ b/system/src/Server/Outfits.php @@ -6,19 +6,24 @@ use MyAAC\Cache\Cache; class Outfits { + private static array $outfits = []; + public static function get() { - return Cache::remember('outfits', 10 * 60, function () { - if (file_exists(config('server_path') . 'config/outfits.toml')) { - $outfits = new TOML\Outfits(); - } - else { - $outfits = new XML\Outfits(); - } + if (count(self::$outfits) == 0) { + self::$outfits = Cache::remember('outfits', 10 * 60, function () { + if (file_exists(config('server_path') . TOML\Outfits::FILE)) { + $outfits = new TOML\Outfits(); + } else { + $outfits = new XML\Outfits(); + } - $outfits->load(); + $outfits->load(); - return $outfits->getOutfits(); - }); + return $outfits->getOutfits(); + }); + } + + return self::$outfits; } } diff --git a/system/src/Server/TOML/Groups.php b/system/src/Server/TOML/Groups.php index 9f6e3793..ae6b642a 100644 --- a/system/src/Server/TOML/Groups.php +++ b/system/src/Server/TOML/Groups.php @@ -8,9 +8,11 @@ class Groups { private array $groups = []; + const FILE = 'config/groups.toml'; + public function load(): void { - $file = config('server_path') . 'config/groups.toml'; + $file = config('server_path') . self::FILE; if(!@file_exists($file)) { error('Error: Cannot load groups.toml. More info in system/logs/error.log file.');