Optimise Zone::class to identify region/hosts/hubs

This commit is contained in:
2024-05-27 10:47:42 +10:00
parent 65b2a2d519
commit 800593d034
2 changed files with 67 additions and 33 deletions

View File

@@ -36,6 +36,44 @@ class Zone extends Model
return $this->belongsTo(Domain::class);
}
public function hosts()
{
return $this->hasMany(Address::class)
->where(function($query) {
return $query
->where(fn($q)=>$q->where('node_id',0)->where('point_id',0))
->orWhere('role',Address::NODE_HC);
})
->FTNorder()
->with(['system','zone.domain']);
}
public function hubs()
{
// @todo we should be able to add to this query, to count children of an address by using a group by?
return $this->hasMany(Address::class)
->where(function($query) {
return $query
->where(fn($q)=>$q->where('point_id',0))
->orWhere('role',Address::NODE_HC);
})
->FTNorder()
->with(['system','zone.domain']);
}
public function regions()
{
return $this->hasMany(Address::class)
->where(function($query) {
return $query
->where(fn($q)=>$q->where('node_id',0)->where('point_id',0))
->orWhere('role',Address::NODE_RC);
})
->orderBy('region_id')
->active()
->with(['system','zone.domain']);
}
public function system()
{
return $this->belongsTo(System::class);