Optimisations to uncollected Items, which fix mail:send, which was only being triggered for mail unsent from yesterday
This commit is contained in:
parent
e56ecaa999
commit
5a74386f5a
@ -250,34 +250,47 @@ class HomeController extends Controller
|
|||||||
|
|
||||||
$r = Address::select([
|
$r = Address::select([
|
||||||
'a.id',
|
'a.id',
|
||||||
'addresses.system_id',
|
'a.system_id',
|
||||||
'addresses.zone_id',
|
'a.zone_id',
|
||||||
'addresses.region_id',
|
'addresses.region_id',
|
||||||
'addresses.host_id',
|
'a.host_id',
|
||||||
'addresses.node_id',
|
'a.node_id',
|
||||||
'addresses.point_id',
|
'a.point_id',
|
||||||
'addresses.hub_id',
|
'addresses.hub_id',
|
||||||
'addresses.role',
|
'addresses.role',
|
||||||
DB::raw('sum(a.uncollected_echomail) as uncollected_echomail'),
|
DB::raw('sum(a.uncollected_echomail) as uncollected_echomail'),
|
||||||
DB::raw('sum(a.uncollected_netmail) as uncollected_netmail'),
|
DB::raw('sum(a.uncollected_netmail) as uncollected_netmail'),
|
||||||
DB::raw('sum(a.uncollected_files) as uncollected_files')
|
DB::raw('sum(a.uncollected_files) as uncollected_files')
|
||||||
])
|
])
|
||||||
->from(Address::UncollectedEchomail()->union(Address::UncollectedNetmail())->union(Address::UncollectedFiles()),'a')
|
->from(
|
||||||
|
Address::UncollectedEchomail()
|
||||||
|
->where('echomails.created_at','<',$this->yesterdayEOD())
|
||||||
|
->union(Address::UncollectedNetmail()
|
||||||
|
->where('netmails.created_at','<',$this->yesterdayEOD())
|
||||||
|
)
|
||||||
|
->union(Address::UncollectedFiles()
|
||||||
|
->where('files.created_at','<',$this->yesterdayEOD())
|
||||||
|
),'a')
|
||||||
->where('systems.active',true)
|
->where('systems.active',true)
|
||||||
->where('addresses.active',TRUE)
|
->where('addresses.active',TRUE)
|
||||||
->where('zones.active',TRUE)
|
->where('zones.active',TRUE)
|
||||||
->where('domains.active',TRUE)
|
->where('domains.active',TRUE)
|
||||||
->when(! ($x=Auth::user()) || (! $x->isAdmin()),function($query) { return $query->where('domains.public',TRUE); })
|
->when(! ($x=Auth::user()) || (! $x->isAdmin()),function($query) { return $query->where('domains.public',TRUE); })
|
||||||
->join('addresses',['addresses.id'=>'a.id'])
|
->join('addresses',['addresses.id'=>'a.id'])
|
||||||
->join('systems',['systems.id'=>'addresses.system_id'])
|
->join('systems',['systems.id'=>'a.system_id'])
|
||||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
->join('zones',['zones.id'=>'addresses.zone_id'])
|
||||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||||
->ftnOrder()
|
->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')
|
->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']);
|
->with(['system','zone.domain']);
|
||||||
|
|
||||||
return view('status')
|
return view('status')
|
||||||
->with('date',$date)
|
->with('date',$date)
|
||||||
->with('uncollected',$r->get());
|
->with('uncollected',$r->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function yesterdayEOD(): Carbon
|
||||||
|
{
|
||||||
|
return Carbon::now()->yesterday()->endOfday();
|
||||||
|
}
|
||||||
}
|
}
|
@ -27,12 +27,12 @@ class MailSend #implements ShouldQueue
|
|||||||
{
|
{
|
||||||
$u = Address::select([
|
$u = Address::select([
|
||||||
'a.id',
|
'a.id',
|
||||||
'addresses.system_id',
|
'a.system_id',
|
||||||
'addresses.zone_id',
|
'a.zone_id',
|
||||||
'addresses.region_id',
|
'addresses.region_id',
|
||||||
'addresses.host_id',
|
'a.host_id',
|
||||||
'addresses.node_id',
|
'a.node_id',
|
||||||
'addresses.point_id',
|
'a.point_id',
|
||||||
'addresses.hub_id',
|
'addresses.hub_id',
|
||||||
'addresses.role',
|
'addresses.role',
|
||||||
DB::raw('sum(a.uncollected_echomail) as uncollected_echomail'),
|
DB::raw('sum(a.uncollected_echomail) as uncollected_echomail'),
|
||||||
@ -45,8 +45,8 @@ class MailSend #implements ShouldQueue
|
|||||||
->where('zones.active',TRUE)
|
->where('zones.active',TRUE)
|
||||||
->where('domains.active',TRUE)
|
->where('domains.active',TRUE)
|
||||||
->join('addresses',['addresses.id'=>'a.id'])
|
->join('addresses',['addresses.id'=>'a.id'])
|
||||||
->join('systems',['systems.id'=>'addresses.system_id'])
|
->join('systems',['systems.id'=>'a.system_id'])
|
||||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
->join('zones',['zones.id'=>'a.zone_id'])
|
||||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||||
->where(function($query) {
|
->where(function($query) {
|
||||||
return $query->whereNull('autohold')
|
return $query->whereNull('autohold')
|
||||||
@ -63,7 +63,7 @@ class MailSend #implements ShouldQueue
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
->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')
|
->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'])
|
->with(['system','zone.domain'])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
@ -99,13 +99,12 @@ class Address extends Model
|
|||||||
public function scopeUncollectedEchomail($query)
|
public function scopeUncollectedEchomail($query)
|
||||||
{
|
{
|
||||||
return $query
|
return $query
|
||||||
->select(['addresses.id',DB::raw('count(*) as uncollected_echomail'),DB::raw('0 as uncollected_netmail'),DB::raw('0 as uncollected_files')])
|
->select(['addresses.id','zone_id','host_id','node_id','point_id','system_id',DB::raw('count(*) as uncollected_echomail'),DB::raw('0 as uncollected_netmail'),DB::raw('0 as uncollected_files')])
|
||||||
->join('echomail_seenby',['echomail_seenby.address_id'=>'addresses.id'])
|
->join('echomail_seenby',['echomail_seenby.address_id'=>'addresses.id'])
|
||||||
->join('echomails',['echomails.id'=>'echomail_seenby.echomail_id'])
|
->join('echomails',['echomails.id'=>'echomail_seenby.echomail_id'])
|
||||||
->whereNotNull('export_at')
|
->whereNotNull('export_at')
|
||||||
->whereNull('sent_at')
|
->whereNull('sent_at')
|
||||||
->whereNull('echomails.deleted_at')
|
->whereNull('echomails.deleted_at')
|
||||||
->where('echomails.created_at','<',$this->yesterdayEOD())
|
|
||||||
->groupBy('addresses.id');
|
->groupBy('addresses.id');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +117,12 @@ class Address extends Model
|
|||||||
public function scopeUncollectedFiles($query)
|
public function scopeUncollectedFiles($query)
|
||||||
{
|
{
|
||||||
return $query
|
return $query
|
||||||
->select(['addresses.id',DB::raw('0 as uncollected_echomail'),DB::raw('0 as uncollected_netmail'),DB::raw('count(*) as uncollected_files')])
|
->select(['addresses.id','zone_id','host_id','node_id','point_id','system_id',DB::raw('0 as uncollected_echomail'),DB::raw('0 as uncollected_netmail'),DB::raw('count(*) as uncollected_files')])
|
||||||
->join('file_seenby',['file_seenby.address_id'=>'addresses.id'])
|
->join('file_seenby',['file_seenby.address_id'=>'addresses.id'])
|
||||||
->join('files',['files.id'=>'file_seenby.file_id'])
|
->join('files',['files.id'=>'file_seenby.file_id'])
|
||||||
->whereNotNull('export_at')
|
->whereNotNull('export_at')
|
||||||
->whereNull('sent_at')
|
->whereNull('sent_at')
|
||||||
->whereNull('files.deleted_at')
|
->whereNull('files.deleted_at')
|
||||||
->where('files.created_at','<',$this->yesterdayEOD())
|
|
||||||
->groupBy('addresses.id');
|
->groupBy('addresses.id');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +135,7 @@ class Address extends Model
|
|||||||
public function scopeUncollectedNetmail($query)
|
public function scopeUncollectedNetmail($query)
|
||||||
{
|
{
|
||||||
return $query
|
return $query
|
||||||
->select(['addresses.id',DB::raw('0 as uncollected_echomail'),DB::raw('count(*) as uncollected_netmail'),DB::raw('0 as uncollected_files')])
|
->select(['addresses.id','zone_id','host_id','node_id','point_id','system_id',DB::raw('0 as uncollected_echomail'),DB::raw('count(*) as uncollected_netmail'),DB::raw('0 as uncollected_files')])
|
||||||
->join('netmails',['netmails.tftn_id'=>'addresses.id'])
|
->join('netmails',['netmails.tftn_id'=>'addresses.id'])
|
||||||
->where(function($query) {
|
->where(function($query) {
|
||||||
return $query->whereRaw(sprintf('(flags & %d) > 0',Message::FLAG_INTRANSIT))
|
return $query->whereRaw(sprintf('(flags & %d) > 0',Message::FLAG_INTRANSIT))
|
||||||
@ -145,7 +143,6 @@ class Address extends Model
|
|||||||
})
|
})
|
||||||
->whereRaw(sprintf('(flags & %d) = 0',Message::FLAG_SENT))
|
->whereRaw(sprintf('(flags & %d) = 0',Message::FLAG_SENT))
|
||||||
->whereNull('netmails.deleted_at')
|
->whereNull('netmails.deleted_at')
|
||||||
->where('netmails.created_at','<',$this->yesterdayEOD())
|
|
||||||
->groupBy('addresses.id');
|
->groupBy('addresses.id');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -947,9 +944,4 @@ class Address extends Model
|
|||||||
{
|
{
|
||||||
return ($this->exists && ($x=$this->system->sessions->where('id',$this->zone_id)->first())) ? ($x->pivot->{$type} ?: '') : NULL;
|
return ($this->exists && ($x=$this->system->sessions->where('id',$this->zone_id)->first())) ? ($x->pivot->{$type} ?: '') : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function yesterdayEOD(): Carbon
|
|
||||||
{
|
|
||||||
return Carbon::now()->yesterday()->endOfday();
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user