Switchout DB to CockroachDB

This commit is contained in:
Deon George
2022-01-01 16:59:35 +11:00
parent afaa7d8bc7
commit 424d6ef39d
28 changed files with 1342 additions and 865 deletions

View File

@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\DB;
use App\Classes\FTN\Packet;
use App\Http\Controllers\DomainController;
use App\Traits\{ScopeActive,UsePostgres};
use App\Traits\ScopeActive;
/**
* @todo Need to stop this from happening:
@@ -24,7 +24,9 @@ use App\Traits\{ScopeActive,UsePostgres};
*/
class Address extends Model
{
use ScopeActive,SoftDeletes,UsePostgres;
use ScopeActive,SoftDeletes;
protected $with = ['zone'];
/* SCOPES */
@@ -337,6 +339,21 @@ class Address extends Model
return ($o && $o->system->active) ? $o : NULL;
}
/**
* Netmail waiting to be sent to this system
*
* @return Collection
*/
public function echomailWaiting(): Collection
{
return Echomail::select(['echomails.*'])
->join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id'])
->where('echomail_seenby.address_id',$this->id)
->whereNull('echomail_seenby.sent_at')
->whereNotNull('echomail_seenby.export_at')
->get();
}
/**
* Get echomail for this node
*
@@ -346,23 +363,17 @@ class Address extends Model
{
$pkt = NULL;
$echomail = DB::table('address_echomail')
->select('echomail_id')
->where('address_id',$this->id)
->whereNull('sent_date')
->get();
if (($x=Echomail::select('*')
->whereIn('_id',$echomail->pluck('echomail_id')))
if (($x=$this->echomailWaiting())
->count())
{
$pkt = $this->getPacket($x->get());
$pkt = $this->getPacket($x);
DB::table('address_echomail')
->whereIn('echomail_id',$echomail->pluck('echomail_id'))
DB::table('echomail_seenby')
->whereIn('echomail_id',$x->pluck('id'))
->where('address_id',$this->id)
->whereNull('sent_date')
->update(['sent_date'=>Carbon::now()]);
->whereNull('sent_at')
->whereNotNull('echomail_seenby.export_at')
->update(['sent_at'=>Carbon::now(),'packet'=>$pkt->name]);
}
return $pkt;
@@ -375,18 +386,19 @@ class Address extends Model
*/
public function getNetmail(): ?Packet
{
if (($x=Netmail::whereIn('tftn_id',(($x=$this->children) ? $x->pluck('id') : collect())->push($this->id))
->where(function($q) {
return $q->whereNull('sent')
->orWhere('sent',FALSE);
}))
->whereNull('local')
$pkt = NULL;
if (($x=$this->netmailWaiting())
->count())
{
return $this->getPacket($x->get());
$pkt = $this->getPacket($x);
DB::table('netmails')
->whereIn('id',$x->pluck('id'))
->update(['sent_at'=>Carbon::now(),'sent_pkt'=>$pkt->name]);
}
return NULL;
return $pkt;
}
/**
@@ -411,6 +423,18 @@ class Address extends Model
return $o;
}
/**
* Netmail waiting to be sent to this system
*
* @return Collection
*/
public function netmailWaiting(): Collection
{
return Netmail::whereIn('tftn_id',(($x=$this->children) ? $x->pluck('id') : collect())->push($this->id))
->whereNull('sent_at')
->get();
}
/**
* Parse a string and split it out as an FTN array
*