Optimise queries for rendering the about page
This commit is contained in:
parent
2edc41b11e
commit
d6e23b9a90
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
|
||||||
@ -10,6 +11,18 @@ use App\Models\{Address,Domain,Zone};
|
|||||||
|
|
||||||
class DomainController extends Controller
|
class DomainController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Daily stats as shown on the about page
|
||||||
|
*
|
||||||
|
* @param Domain $o
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function api_daily_stats(Request $request): Collection
|
||||||
|
{
|
||||||
|
$do = Domain::where('name',$request->name)->firstOrFail();
|
||||||
|
return $do->daily_area_stats();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add or edit a domain
|
* Add or edit a domain
|
||||||
*/
|
*/
|
||||||
|
@ -139,10 +139,16 @@ class Domain extends Model
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isManaged(): bool
|
||||||
|
{
|
||||||
|
return our_address()->pluck('zone.domain')->pluck('id')->contains($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if this zone is managed by this host
|
* Determine if this zone is managed by this host
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @deprecated use self::isManaged();
|
||||||
*/
|
*/
|
||||||
public function managed(): bool
|
public function managed(): bool
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See if the user is already a member of the chosen network
|
* See if the user is already a member of the chosen network
|
||||||
*
|
*
|
||||||
@ -103,6 +102,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function isZC(): bool
|
public function isZC(): bool
|
||||||
{
|
{
|
||||||
|
$this->load(['systems.addresses']);
|
||||||
return $this->zc()->count() > 0;
|
return $this->zc()->count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,16 +91,26 @@ if (! function_exists('hexstr')) {
|
|||||||
*/
|
*/
|
||||||
function our_address(Domain $do=NULL,Address $ao=NULL): Collection|Address|NULL
|
function our_address(Domain $do=NULL,Address $ao=NULL): Collection|Address|NULL
|
||||||
{
|
{
|
||||||
$our = Setup::findOrFail(config('app.id'))->system->akas;
|
static $so = NULL;
|
||||||
|
static $our = NULL;
|
||||||
|
|
||||||
|
if (! $so)
|
||||||
|
$so = Setup::findOrFail(config('app.id'));
|
||||||
|
|
||||||
|
if (! $our) {
|
||||||
|
$so->load(['system.akas.zone.domain']);
|
||||||
|
$our = $so->system->akas;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter = $our;
|
||||||
if ($do)
|
if ($do)
|
||||||
$our = $our->filter(function($item) use ($do) { return $item->zone->domain_id === $do->id; })->sortBy('role');
|
$filter = $our->filter(function($item) use ($do) { return $item->zone->domain_id === $do->id; })->sortBy('role');
|
||||||
|
|
||||||
// If we are looking for a specific address, and there is only 1 result, return it, otherwise return what we have
|
// If we are looking for a specific address, and there is only 1 result, return it, otherwise return what we have
|
||||||
if ($ao && config('fido.strict') && ($x=$our->filter(function($item) use ($ao) { return $item->role <= $ao->role; })->sortBy('role'))->count())
|
if ($ao && config('fido.strict') && ($x=$filter->filter(function($item) use ($ao) { return $item->role <= $ao->role; })->sortBy('role'))->count())
|
||||||
$our = $x;
|
$our = $x;
|
||||||
|
|
||||||
return $ao ? $our->last() : $our;
|
return $ao ? $our->last() : ($do ? $filter : $our);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +125,7 @@
|
|||||||
@js('highcharts')
|
@js('highcharts')
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
Highcharts.chart('network_traffic', {
|
var chart = Highcharts.chart('network_traffic', {
|
||||||
chart: {
|
chart: {
|
||||||
type: 'spline',
|
type: 'spline',
|
||||||
zoomType: 'x',
|
zoomType: 'x',
|
||||||
@ -176,16 +176,30 @@
|
|||||||
@foreach (\App\Models\Domain::active()
|
@foreach (\App\Models\Domain::active()
|
||||||
->when(((! $user) || (! $user->isAdmin())),function($query) { return $query->public()->active(); })
|
->when(((! $user) || (! $user->isAdmin())),function($query) { return $query->public()->active(); })
|
||||||
->orderBy('name')
|
->orderBy('name')
|
||||||
->with(['echoareas'])->get() as $o)
|
->with(['echoareas'])
|
||||||
|
->get() as $o)
|
||||||
@if ($o->managed())
|
@if ($o->managed())
|
||||||
{
|
{
|
||||||
name: '{{ $o->name }}',
|
name: '{{ $o->name }}',
|
||||||
data: {!! $o->daily_area_stats() !!},
|
data: [],
|
||||||
dashStyle: 'ShortDot',
|
dashStyle: 'ShortDot',
|
||||||
},
|
},
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
chart.series.forEach(function(item) {
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/domain/daily',
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json',
|
||||||
|
data : {name: item.name},
|
||||||
|
success: function(data) {
|
||||||
|
item.setData(data);
|
||||||
|
},
|
||||||
|
cache: false
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
@append
|
@append
|
@ -14,8 +14,9 @@
|
|||||||
<dt>Explore Networks</dt>
|
<dt>Explore Networks</dt>
|
||||||
@foreach (\App\Models\Domain::select(['id','name'])
|
@foreach (\App\Models\Domain::select(['id','name'])
|
||||||
->when(((! $user) || (! $user->isAdmin())),function($query) { return $query->public()->active(); })
|
->when(((! $user) || (! $user->isAdmin())),function($query) { return $query->public()->active(); })
|
||||||
->orderBy('name')->get() as $o)
|
->orderBy('name')
|
||||||
@if ($o->managed())
|
->get() as $o)
|
||||||
|
@if ($o->isManaged())
|
||||||
<dd><a href="{{ url('domain/view',['id'=>$o->id]) }}">{{ $o->name }}</a></dd>
|
<dd><a href="{{ url('domain/view',['id'=>$o->id]) }}">{{ $o->name }}</a></dd>
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
|
@ -14,3 +14,5 @@ use App\Http\Controllers\{DomainController,SystemController,ZoneController};
|
|||||||
| is assigned the "api" middleware group. Enjoy building your API!
|
| is assigned the "api" middleware group. Enjoy building your API!
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Route::get('/domain/daily',[DomainController::class,'api_daily_stats']);
|
Loading…
Reference in New Issue
Block a user