From 19338edcb67d24739635e8c8667e5ece9fa324a0 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 23 Nov 2023 21:55:39 +1100 Subject: [PATCH] Optimise the queries used to display packet contents and show DBID if msgid is not available --- app/Http/Controllers/HomeController.php | 25 ++++++++++++----------- app/Models/Netmail.php | 3 ++- resources/views/packet.blade.php | 8 +++++++- resources/views/widgets/message.blade.php | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 79ccdc8..8d3f0ae 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -44,8 +44,7 @@ class HomeController extends Controller public function packet_contents(System $o,string $packet) { - $nm = Netmail::select('netmails.*') - ->distinct() + $nm = Netmail::select(['netmails.id','fftn_id','tftn_id','netmails.datetime']) ->leftJoin('netmail_path',['netmail_path.netmail_id'=>'netmails.id']) ->where(function($query) use ($o,$packet) { return $query @@ -54,21 +53,23 @@ class HomeController extends Controller }) ->get(); - $em = Echomail::select('echomails.*') - ->distinct() + $em = Echomail::select(['echomails.id','fftn_id','echoarea_id','msgid','datetime']) ->leftJoin('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id']) - ->leftJoin('echomail_path',['echomail_path.echomail_id'=>'echomails.id']) ->where(function($query) use ($o,$packet) { return $query ->where('sent_pkt',$packet) ->whereIn('echomail_seenby.address_id',$o->addresses->pluck('id')); - }) - ->orWhere(function($query) use ($o,$packet) { - return $query - ->where('recv_pkt',$packet) - ->whereIn('echomail_path.address_id',$o->addresses->pluck('id')); - }) - ->with('echoarea') + }) + ->union( + Echomail::select(['echomails.id','fftn_id','echoarea_id','msgid','datetime']) + ->leftJoin('echomail_path',['echomail_path.echomail_id'=>'echomails.id']) + ->where(function($query) use ($o,$packet) { + return $query + ->where('recv_pkt',$packet) + ->whereIn('echomail_path.address_id',$o->addresses->pluck('id')); + }) + ) + ->with(['echoarea']) ->get(); return view('packet') diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index 6194dbc..cbb1666 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -154,7 +154,8 @@ final class Netmail extends Model implements Packet public function tftn() { return $this - ->belongsTo(Address::class); + ->belongsTo(Address::class) + ->withTrashed(); } /* METHODS */ diff --git a/resources/views/packet.blade.php b/resources/views/packet.blade.php index 83f3ab8..2c4e426 100644 --- a/resources/views/packet.blade.php +++ b/resources/views/packet.blade.php @@ -17,7 +17,13 @@ {{ $oo->fftn->ftn }} {{ $oo->tftn->ftn }} - {{ $oo->msgid }} + + @if ($oo->msgid) + {{ $oo->msgid }} + @else + [{{ $oo->id }}] + @endif + {{ $oo->datetime }} @endforeach diff --git a/resources/views/widgets/message.blade.php b/resources/views/widgets/message.blade.php index 674e56c..3cc89c0 100644 --- a/resources/views/widgets/message.blade.php +++ b/resources/views/widgets/message.blade.php @@ -64,7 +64,7 @@ use App\Classes\FTN\Message;
PATH:
{!! optimize_path($msg->pathorder())->join(' -> ') !!} - @if ($msg->rogue_path->count()) + @if (($msg instanceof \App\Models\Echomail) && $msg->rogue_path->count())
[NOTE: Some path values couldnt be identified - ({{ $msg->rogue_path->join(',') }})] @endif