Optimize the SQL queries that finds unsent echomail,netmail and files
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Repat\LaravelJobs\Job;
|
||||
|
||||
use App\Models\Address;
|
||||
use App\Traits\HubStats;
|
||||
|
||||
class MailSend #implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use HubStats,Dispatchable;
|
||||
|
||||
private const LOGKEY = 'JMS';
|
||||
|
||||
@@ -25,46 +25,22 @@ class MailSend #implements ShouldQueue
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$u = Address::select([
|
||||
'a.id',
|
||||
'a.system_id',
|
||||
'a.zone_id',
|
||||
'addresses.region_id',
|
||||
'a.host_id',
|
||||
'a.node_id',
|
||||
'a.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()->union(Address::UncollectedNetmailTotal())->union(Address::UncollectedFilesTotal()),'a')
|
||||
->where('systems.active',true)
|
||||
->where('addresses.active',TRUE)
|
||||
->where('zones.active',TRUE)
|
||||
->where('domains.active',TRUE)
|
||||
->join('addresses',['addresses.id'=>'a.id'])
|
||||
->join('systems',['systems.id'=>'a.system_id'])
|
||||
->join('zones',['zones.id'=>'a.zone_id'])
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->groupBy('a.system_id','a.id','a.zone_id','addresses.region_id','a.host_id','a.node_id','a.point_id','addresses.hub_id','addresses.role')
|
||||
->with(['system','zone.domain'])
|
||||
->get();
|
||||
|
||||
// Return the system we poll
|
||||
$u = $u->transform(function($item) {
|
||||
if ($x=$item->uplink()) {
|
||||
$x->uncollected_echomail = $item->uncollected_echomail;
|
||||
$x->uncollected_netmail = $item->uncollected_netmail;
|
||||
$x->uncollected_files = $item->uncollected_files;
|
||||
$u = $this
|
||||
->HubStats(Carbon::now())
|
||||
->get()
|
||||
->transform(function($item) {
|
||||
if ($x=$item->uplink()) {
|
||||
$x->uncollected_echomail = $item->uncollected_echomail;
|
||||
$x->uncollected_netmail = $item->uncollected_netmail;
|
||||
$x->uncollected_files = $item->uncollected_files;
|
||||
|
||||
return $x;
|
||||
return $x;
|
||||
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
})
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
})
|
||||
->filter(function($item) {
|
||||
if ($item->system->autohold)
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user