Mail bundling and processing performance improvements
This commit is contained in:
@@ -209,6 +209,7 @@ class Address extends Model
|
||||
$o = $query
|
||||
->where('region_id',$ftn['n'])
|
||||
->where('host_id',$ftn['n'])
|
||||
->with(['system:id,active'])
|
||||
->first();
|
||||
|
||||
// Look for a normal address
|
||||
@@ -223,15 +224,16 @@ class Address extends Model
|
||||
})
|
||||
->orWhere('host_id',$ftn['n']);
|
||||
})
|
||||
->with(['system:id,active'])
|
||||
->first();
|
||||
|
||||
// Check and see if we are a flattened domain, our address might be available with a different zone.
|
||||
// This occurs when we are parsing 2D addresses from SEEN-BY, but we have the zone
|
||||
if (! $o && ($ftn['p'] === 0)) {
|
||||
if ($ftn['d'])
|
||||
$do = Domain::where(['name'=>$ftn['d']])->single();
|
||||
$do = Domain::select('flatten')->where(['name'=>$ftn['d']])->single();
|
||||
else {
|
||||
$zo = Zone::where('zone_id',$ftn['z'])->where('default',TRUE)->single();
|
||||
$zo = Zone::where('zone_id',$ftn['z'])->where('default',TRUE)->with(['domain:id,flatten'])->single();
|
||||
$do = $zo?->domain;
|
||||
}
|
||||
|
||||
@@ -393,8 +395,11 @@ class Address extends Model
|
||||
*/
|
||||
public function scopeFTN($query)
|
||||
{
|
||||
return $query->select(['addresses.zone_id','host_id','node_id','point_id'])
|
||||
->with('zone.domain');
|
||||
return $query->select(['id','addresses.zone_id','host_id','node_id','point_id'])
|
||||
->with([
|
||||
'zone:zones.id,domain_id,zone_id',
|
||||
'zone.domain:domains.id,name',
|
||||
]);
|
||||
}
|
||||
|
||||
public function scopeFTNOrder($query)
|
||||
@@ -597,9 +602,9 @@ class Address extends Model
|
||||
public function nodes_hub(): HasMany
|
||||
{
|
||||
return $this->hasMany(Address::class,'hub_id','id')
|
||||
->FTN()
|
||||
->active()
|
||||
->FTNorder()
|
||||
->with(['zone.domain']);
|
||||
->FTNorder();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -618,7 +623,7 @@ class Address extends Model
|
||||
->whereNot('id',$this->id)
|
||||
->active()
|
||||
->FTNorder()
|
||||
->with(['zone.domain']),
|
||||
->with(['zone:id,domain_id,zone_id']),
|
||||
$this,
|
||||
NULL,
|
||||
($this->role_id === self::NODE_NC) ? 'id' : NULL)
|
||||
@@ -642,7 +647,7 @@ class Address extends Model
|
||||
->whereNot('id',$this->id)
|
||||
->active()
|
||||
->FTNorder()
|
||||
->with(['zone.domain']),
|
||||
->with(['zone:id,domain_id,zone_id']),
|
||||
$this,
|
||||
NULL,
|
||||
($this->role_id !== self::NODE_POINT) ? 'id' : NULL)
|
||||
@@ -659,7 +664,7 @@ class Address extends Model
|
||||
->whereNot('id',$this->id)
|
||||
->active()
|
||||
->FTNorder()
|
||||
->with(['zone.domain']),
|
||||
->with(['zone:id,domain_id,zone_id']),
|
||||
$this,
|
||||
NULL,
|
||||
($this->role_id === self::NODE_RC) ? 'id' : NULL)
|
||||
@@ -675,7 +680,7 @@ class Address extends Model
|
||||
->whereNot('id',$this->id)
|
||||
->active()
|
||||
->FTNorder()
|
||||
->with(['zone.domain']),
|
||||
->with(['zone:id,domain_id,zone_id']),
|
||||
$this,
|
||||
NULL,
|
||||
($this->role_id === self::NODE_ZC) ? 'id' : NULL)
|
||||
@@ -722,6 +727,9 @@ class Address extends Model
|
||||
*/
|
||||
public function getFTNAttribute(): string
|
||||
{
|
||||
if (! $this->relationLoaded('zone'))
|
||||
$this->load(['zone:id,domain_id,zone_id','zone.domain:domains.id,name']);
|
||||
|
||||
return sprintf('%s@%s',$this->getFTN4DAttribute(),$this->zone->domain->name);
|
||||
}
|
||||
|
||||
@@ -732,11 +740,17 @@ class Address extends Model
|
||||
|
||||
public function getFTN3DAttribute(): string
|
||||
{
|
||||
if (! $this->relationLoaded('zone'))
|
||||
$this->load(['zone:id,domain_id,zone_id']);
|
||||
|
||||
return sprintf('%d:%s',$this->zone->zone_id,$this->getFTN2DAttribute());
|
||||
}
|
||||
|
||||
public function getFTN4DAttribute(): string
|
||||
{
|
||||
if (! $this->relationLoaded('zone'))
|
||||
$this->load(['zone:id,domain_id,zone_id']);
|
||||
|
||||
return sprintf('%s.%d',$this->getFTN3DAttribute(),$this->point_id);
|
||||
}
|
||||
|
||||
@@ -998,20 +1012,28 @@ class Address extends Model
|
||||
/**
|
||||
* Echomail waiting to be sent to this system
|
||||
*
|
||||
* @param int|null $max
|
||||
* @return Builder
|
||||
*/
|
||||
public function echomailWaiting(int $max=NULL): Builder
|
||||
public function echomailWaiting(): Builder
|
||||
{
|
||||
$echomails = $this
|
||||
->UncollectedEchomail()
|
||||
->select('echomails.id')
|
||||
->where('addresses.id',$this->id)
|
||||
->when($max,function($query) use ($max) { return $query->limit($max); })
|
||||
->groupBy(['echomails.id'])
|
||||
->get();
|
||||
|
||||
return Echomail::whereIn('id',$echomails->pluck('id'));
|
||||
return Echomail::select('echomails.*')
|
||||
->join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id'])
|
||||
->where('address_id',$this->id)
|
||||
->whereNull('echomails.deleted_at')
|
||||
->whereNotNull('export_at')
|
||||
->whereNull('sent_at')
|
||||
->orderby('id')
|
||||
->with([
|
||||
'tagline:id,value',
|
||||
'tearline:id,value',
|
||||
'origin:id,value',
|
||||
'echoarea:id,name,domain_id',
|
||||
'echoarea.domain:id,name',
|
||||
'fftn:id,zone_id,host_id,node_id,point_id',
|
||||
'fftn.zone:id,domain_id,zone_id',
|
||||
'fftn.zone.domain:id,name',
|
||||
])
|
||||
->dontCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1076,11 +1098,11 @@ class Address extends Model
|
||||
*/
|
||||
public function getEchomail(): ?Packet
|
||||
{
|
||||
if (($num=$this->echomailWaiting())->count()) {
|
||||
Log::info(sprintf('%s:= Got [%d] echomails for [%s] for sending',self::LOGKEY,$num->count(),$this->ftn));
|
||||
if ($count=($num=$this->echomailWaiting())->count()) {
|
||||
Log::info(sprintf('%s:= Got [%d] echomails for [%s] for sending',self::LOGKEY,$count,$this->ftn));
|
||||
|
||||
// Limit to max messages
|
||||
if ($num->count() > $this->system->pkt_msgs)
|
||||
if ($count > $this->system->pkt_msgs)
|
||||
Log::notice(sprintf('%s:= Only sending [%d] echomails for [%s]',self::LOGKEY,$this->system->pkt_msgs,$this->ftn));
|
||||
|
||||
return $this->system->packet($this)->mail($num->take($this->system->pkt_msgs)->get());
|
||||
|
Reference in New Issue
Block a user