Optimised our sending and receiving of items
This commit is contained in:
@@ -9,19 +9,10 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\Packet;
|
||||
use App\Classes\FTN\{Message,Packet};
|
||||
use App\Http\Controllers\DomainController;
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
/**
|
||||
* @todo Need to stop this from happening:
|
||||
* In this example nn:3/1 can be defined 3 different ways.
|
||||
* + id | zone_id | region_id | host_id | node_id | point_id | status | role | system_id | hub_id
|
||||
* + ----+---------+-----------+---------+---------+----------+--------+------+-----------+--------
|
||||
* + 533 | 6 | 3 | 0 | 1 | 0 | | 4 | 1 |
|
||||
* + 534 | 6 | n | 3 | 1 | 0 | | 2 | 1 |
|
||||
* + 535 | 6 | 0 | 3 | 1 | 0 | | 2 | 1 |
|
||||
*/
|
||||
class Address extends Model
|
||||
{
|
||||
private const LOGKEY = 'MA-';
|
||||
@@ -338,7 +329,7 @@ class Address extends Model
|
||||
|
||||
public function getFTN3DAttribute(): string
|
||||
{
|
||||
return sprintf('%d:%d/%d',$this->zone->zone_id,$this->host_id ?: $this->region_id,$this->node_id);
|
||||
return sprintf('%d:%s',$this->zone->zone_id,$this->getFTN2DAttribute());
|
||||
}
|
||||
|
||||
public function getFTN4DAttribute(): string
|
||||
@@ -546,8 +537,8 @@ class Address extends Model
|
||||
public function echomailWaiting(): Collection
|
||||
{
|
||||
return $this->echomails()
|
||||
->whereNull('echomail_seenby.sent_at')
|
||||
->whereNotNull('echomail_seenby.export_at')
|
||||
->whereNull('sent_at')
|
||||
->whereNotNull('export_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
@@ -559,8 +550,8 @@ class Address extends Model
|
||||
public function filesWaiting(): Collection
|
||||
{
|
||||
return $this->files()
|
||||
->whereNull('file_seenby.sent_at')
|
||||
->whereNotNull('file_seenby.export_at')
|
||||
->whereNull('sent_at')
|
||||
->whereNotNull('export_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
@@ -597,8 +588,7 @@ class Address extends Model
|
||||
->whereIn('echomail_id',$x->pluck('id'))
|
||||
->where('address_id',$this->id)
|
||||
->whereNull('sent_at')
|
||||
->whereNull('sent_pkt')
|
||||
->whereNotNull('echomail_seenby.export_at')
|
||||
->whereNotNull('export_at')
|
||||
->update(['sent_pkt'=>$pkt->name]);
|
||||
}
|
||||
|
||||
@@ -610,25 +600,11 @@ class Address extends Model
|
||||
*
|
||||
* @param bool $update
|
||||
* @return Collection
|
||||
* @deprecated use filesWaiting() directly
|
||||
*/
|
||||
public function getFiles(bool $update=TRUE): Collection
|
||||
{
|
||||
if (($files=$this->filesWaiting())
|
||||
->count())
|
||||
{
|
||||
Log::debug(sprintf('%s:= Got [%d] files for [%s] for sending',self::LOGKEY,$files->count(),$this->ftn));
|
||||
|
||||
// @todo This should be transactional, incase the transfer fails
|
||||
if ($files->count() && $update)
|
||||
DB::table('file_seenby')
|
||||
->whereIn('file_id',$files->pluck('id'))
|
||||
->where('address_id',$this->id)
|
||||
->whereNull('sent_at')
|
||||
->whereNotNull('export_at')
|
||||
->update(['sent_at'=>Carbon::now()]);
|
||||
}
|
||||
|
||||
return $files;
|
||||
return $this->filesWaiting();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -705,7 +681,11 @@ class Address extends Model
|
||||
public function netmailWaiting(): Collection
|
||||
{
|
||||
return Netmail::whereIn('tftn_id',(($x=$this->children) ? $x->pluck('id') : collect())->push($this->id))
|
||||
->where('local',FALSE)
|
||||
->where(function($query) {
|
||||
return $query->whereRaw(sprintf('(flags & %d) > 0',Message::FLAG_INTRANSIT))
|
||||
->orWhereRaw(sprintf('(flags & %d) > 0',Message::FLAG_LOCAL));
|
||||
})
|
||||
->whereRaw(sprintf('(flags & %d) = 0',Message::FLAG_SENT))
|
||||
->whereNull('sent_at')
|
||||
->get();
|
||||
}
|
||||
|
Reference in New Issue
Block a user