Optimize the SQL queries that finds unsent echomail,netmail and files
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\Dynamic;
|
||||
use App\Models\Address;
|
||||
use App\Traits\HubStats as HubStatsTrait;
|
||||
|
||||
/**
|
||||
* This method will generate the hub status for an upstream Host/RC/ZC
|
||||
@@ -18,6 +19,8 @@ use App\Models\Address;
|
||||
*/
|
||||
class HubStats extends Dynamic
|
||||
{
|
||||
use HubStatsTrait;
|
||||
|
||||
private const LOGKEY = 'DHS';
|
||||
|
||||
private string $name = '';
|
||||
@@ -32,41 +35,8 @@ class HubStats extends Dynamic
|
||||
{
|
||||
$date = Carbon::now()->yesterday()->endOfday();
|
||||
|
||||
$r = Address::select([
|
||||
'a.id',
|
||||
'addresses.system_id',
|
||||
'addresses.zone_id',
|
||||
'addresses.region_id',
|
||||
'addresses.host_id',
|
||||
'addresses.node_id',
|
||||
'addresses.point_id',
|
||||
'addresses.hub_id',
|
||||
'addresses.role',
|
||||
DB::raw('sum(a.uncollected_echomail) as uncollected_echomail'),
|
||||
DB::raw('sum(a.uncollected_netmail) as uncollected_netmail'),
|
||||
DB::raw('sum(a.uncollected_files) as uncollected_files')
|
||||
])
|
||||
->from(
|
||||
Address::UncollectedEchomailTotal()
|
||||
->where('echomails.created_at','<',$date)
|
||||
->union(Address::UncollectedNetmailTotal()
|
||||
->where('netmails.created_at','<',$date)
|
||||
)
|
||||
->union(Address::UncollectedFilesTotal()
|
||||
->where('files.created_at','<',$date)
|
||||
),'a')
|
||||
->where('systems.active',true)
|
||||
->where('addresses.active',TRUE)
|
||||
->where('zones.active',TRUE)
|
||||
->where('domains.active',TRUE)
|
||||
->where('zones.id',$this->ao->zone_id)
|
||||
->join('addresses',['addresses.id'=>'a.id'])
|
||||
->join('systems',['systems.id'=>'addresses.system_id'])
|
||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->ftnOrder()
|
||||
->groupBy('addresses.system_id','a.id','addresses.zone_id','addresses.region_id','addresses.host_id','addresses.node_id','addresses.point_id','addresses.hub_id','addresses.role')
|
||||
->with(['system','zone.domain']);
|
||||
$r = $this->HubStats($date)
|
||||
->where('zones.id',$this->ao->zone_id);
|
||||
|
||||
$header = "| %-12s | %4d | %3d | %3d | %16s | %5s | %5s |\r\n";
|
||||
|
||||
|
Reference in New Issue
Block a user