Mail bundling and processing performance improvements
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 48s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m57s
Create Docker Image / Final Docker Image Manifest (push) Successful in 12s

This commit is contained in:
2024-06-17 18:33:48 +09:30
parent c9700fbd0c
commit 1b2358b5a9
15 changed files with 202 additions and 184 deletions

View File

@@ -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());

View File

@@ -62,7 +62,8 @@ class Domain extends Model
public function zones()
{
return $this->hasMany(Zone::class);
return $this->hasMany(Zone::class)
->select(['id','zone_id','domain_id']);
}
/* ATTRIBUTES */

View File

@@ -280,12 +280,15 @@ final class Echomail extends Model implements Packet
public function echoarea()
{
return $this->belongsTo(Echoarea::class);
return $this->belongsTo(Echoarea::class)
->select('id','active','name','domain_id','security','automsgs')
->with(['domain:id,name']);
}
public function seenby()
{
return $this->belongsToMany(Address::class,'echomail_seenby')
->select(['id','zone_id','host_id','node_id'])
->withPivot(['export_at','sent_at','sent_pkt'])
->FTN2DOrder();
}
@@ -293,6 +296,7 @@ final class Echomail extends Model implements Packet
public function path()
{
return $this->belongsToMany(Address::class,'echomail_path')
->select(['addresses.id','zone_id','host_id','node_id'])
->withPivot(['id','parent_id','recv_pkt','recv_at'])
->orderBy('id','DESC');
}

View File

@@ -110,6 +110,7 @@ class System extends Model
public function sessions()
{
return $this->belongsToMany(Zone::class)
->select(['id','zones.zone_id','domain_id','active'])
->withPivot(['sespass','pktpass','ticpass','fixpass','zt_ipv4','zt_ipv6','default'])
->dontCache();
}