Optimise the queries used to display packet contents and show DBID if msgid is not available

This commit is contained in:
Deon George 2023-11-23 21:55:39 +11:00
parent b3dfca5b89
commit 19338edcb6
4 changed files with 23 additions and 15 deletions

View File

@ -44,8 +44,7 @@ class HomeController extends Controller
public function packet_contents(System $o,string $packet) public function packet_contents(System $o,string $packet)
{ {
$nm = Netmail::select('netmails.*') $nm = Netmail::select(['netmails.id','fftn_id','tftn_id','netmails.datetime'])
->distinct()
->leftJoin('netmail_path',['netmail_path.netmail_id'=>'netmails.id']) ->leftJoin('netmail_path',['netmail_path.netmail_id'=>'netmails.id'])
->where(function($query) use ($o,$packet) { ->where(function($query) use ($o,$packet) {
return $query return $query
@ -54,21 +53,23 @@ class HomeController extends Controller
}) })
->get(); ->get();
$em = Echomail::select('echomails.*') $em = Echomail::select(['echomails.id','fftn_id','echoarea_id','msgid','datetime'])
->distinct()
->leftJoin('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id']) ->leftJoin('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id'])
->leftJoin('echomail_path',['echomail_path.echomail_id'=>'echomails.id'])
->where(function($query) use ($o,$packet) { ->where(function($query) use ($o,$packet) {
return $query return $query
->where('sent_pkt',$packet) ->where('sent_pkt',$packet)
->whereIn('echomail_seenby.address_id',$o->addresses->pluck('id')); ->whereIn('echomail_seenby.address_id',$o->addresses->pluck('id'));
}) })
->orWhere(function($query) use ($o,$packet) { ->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 return $query
->where('recv_pkt',$packet) ->where('recv_pkt',$packet)
->whereIn('echomail_path.address_id',$o->addresses->pluck('id')); ->whereIn('echomail_path.address_id',$o->addresses->pluck('id'));
}) })
->with('echoarea') )
->with(['echoarea'])
->get(); ->get();
return view('packet') return view('packet')

View File

@ -154,7 +154,8 @@ final class Netmail extends Model implements Packet
public function tftn() public function tftn()
{ {
return $this return $this
->belongsTo(Address::class); ->belongsTo(Address::class)
->withTrashed();
} }
/* METHODS */ /* METHODS */

View File

@ -17,7 +17,13 @@
<tr> <tr>
<td>{{ $oo->fftn->ftn }}</td> <td>{{ $oo->fftn->ftn }}</td>
<td>{{ $oo->tftn->ftn }}</td> <td>{{ $oo->tftn->ftn }}</td>
<td>{{ $oo->msgid }}</td> <td>
@if ($oo->msgid)
{{ $oo->msgid }}
@else
<small>[{{ $oo->id }}]</small>
@endif
</td>
<td>{{ $oo->datetime }}</td> <td>{{ $oo->datetime }}</td>
</tr> </tr>
@endforeach @endforeach

View File

@ -64,7 +64,7 @@ use App\Classes\FTN\Message;
<div class="col-8"> <div class="col-8">
PATH: <br><strong class="highlight">{!! optimize_path($msg->pathorder())->join('</strong> -> <strong class="highlight">') !!}</strong> PATH: <br><strong class="highlight">{!! optimize_path($msg->pathorder())->join('</strong> -> <strong class="highlight">') !!}</strong>
@if ($msg->rogue_path->count()) @if (($msg instanceof \App\Models\Echomail) && $msg->rogue_path->count())
<br><small>[<strong>NOTE</strong>: Some path values couldnt be identified - ({{ $msg->rogue_path->join(',') }})]</small> <br><small>[<strong>NOTE</strong>: Some path values couldnt be identified - ({{ $msg->rogue_path->join(',') }})]</small>
@endif @endif
</div> </div>