Optimise the setting of our configuration via Setup::class, optimise the calculation of our_addresses()
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
use App\Models\{Address,Domain,Setup};
|
||||
|
||||
@@ -93,33 +93,29 @@ if (! function_exists('hexstr')) {
|
||||
*/
|
||||
function our_address(Domain|Address $o=NULL): Collection|Address|NULL
|
||||
{
|
||||
$so = Cache::remember('so',5,function() {
|
||||
return Setup::findOrFail(config('app.id'));
|
||||
});
|
||||
if (! Config::has('setup'))
|
||||
Config::set('setup',Setup::findOrFail(config('app.id')));
|
||||
|
||||
$our = Cache::remember(sprintf('%d-akas',$so->system_id),60,function() use ($so) {
|
||||
$so->load([
|
||||
'system:id,name',
|
||||
'system.akas:addresses.id,addresses.zone_id,region_id,host_id,node_id,point_id,addresses.system_id,addresses.active,role',
|
||||
'system.akas.zone:id,domain_id,zone_id',
|
||||
'system.akas.zone.domain:id,name',
|
||||
]);
|
||||
|
||||
return $so->system->akas;
|
||||
});
|
||||
$so = Config::get('setup');
|
||||
$so->loadMissing([
|
||||
'system:id,name',
|
||||
'system.akas:addresses.id,addresses.zone_id,region_id,host_id,node_id,point_id,addresses.system_id,addresses.active,role',
|
||||
'system.akas.zone:id,domain_id,zone_id',
|
||||
'system.akas.zone.domain:id,name',
|
||||
]);
|
||||
|
||||
// If we dont have any addresses
|
||||
if ($our->count() === 0)
|
||||
if ($so->system->akas->count() === 0)
|
||||
return NULL;
|
||||
|
||||
// We havent asked for an address/domain, so we'll return them all.
|
||||
if (is_null($o))
|
||||
return $our;
|
||||
return $so->system->akas;
|
||||
|
||||
// We are requesting a list of addresses for a Domain, or a specific Address, and we have more than 1
|
||||
switch (get_class($o)) {
|
||||
case Address::class:
|
||||
$filter = $our
|
||||
$filter = $so->system->akas
|
||||
->filter(fn($item)=>$item->zone->domain_id === $o->zone->domain_id)
|
||||
->sortBy('role_id');
|
||||
|
||||
@@ -130,7 +126,7 @@ function our_address(Domain|Address $o=NULL): Collection|Address|NULL
|
||||
return $filter->count() ? $filter->last()->unsetRelation('nodes_hub') : NULL;
|
||||
|
||||
case Domain::class:
|
||||
return $our
|
||||
return $so->system->akas
|
||||
->filter(fn($item)=>$item->zone->domain_id === $o->id)
|
||||
->sortBy('role_id');
|
||||
|
||||
|
Reference in New Issue
Block a user