Performance workarounds as a result of 1bba21 - need to work on with()

This commit is contained in:
Deon George 2021-07-02 15:10:22 +10:00
parent 1bba21dcef
commit 90190bb301
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
5 changed files with 13 additions and 10 deletions

View File

@ -35,8 +35,10 @@ class HomeController extends Controller
public function home(User $o): View public function home(User $o): View
{ {
// If we are passed a user to view, we'll open up their home page. // If we are passed a user to view, we'll open up their home page.
if ($o->exists) if ($o->exists) {
$o->load(['accounts','services']);
return View('u.home',['o'=>$o]); return View('u.home',['o'=>$o]);
}
// If User was null, then test and see what type of logged on user we have // If User was null, then test and see what type of logged on user we have
$o = Auth::user(); $o = Auth::user();

View File

@ -17,6 +17,7 @@
<div class="info-box-content"> <div class="info-box-content">
<span class="info-box-text">Active Services</span> <span class="info-box-text">Active Services</span>
<!-- @todo This should count of inactive services too -->
<span class="info-box-number">{{ $o->services->count() }} <small>/{{ $o->services->count() }}</small></span> <span class="info-box-number">{{ $o->services->count() }} <small>/{{ $o->services->count() }}</small></span>
</div> </div>
</div> </div>
@ -28,7 +29,7 @@
<div class="info-box-content"> <div class="info-box-content">
<span class="info-box-text">Account Balance</span> <span class="info-box-text">Account Balance</span>
<span class="info-box-number"><small>$</small> {{ number_format($o->invoices_due->sum('due'),2) }}</span> <span class="info-box-number"><small>$</small> {{ number_format(($x=$o->invoices()->with(['items.taxes','paymentitems.payment','account'])->get()->where('due','>',0))->sum('due'),2) }}</span>
</div> </div>
</div> </div>
</div> </div>
@ -39,7 +40,7 @@
<div class="info-box-content"> <div class="info-box-content">
<span class="info-box-text">Invoices Due</span> <span class="info-box-text">Invoices Due</span>
<span class="info-box-number">{{ $o->invoices_due->count() }}</span> <span class="info-box-number">{{ $x->count() }}</span>
</div> </div>
</div> </div>
</div> </div>

View File

@ -5,7 +5,7 @@
</div> </div>
<div class="card-body"> <div class="card-body">
@if($o->invoices->where('due','>',0)->count()) @if(($x=$o->invoices()->with(['items.taxes','paymentitems.payment','account'])->get()->where('due','>',0))->count())
<table class="table table-bordered w-100" id="invoices_due"> <table class="table table-bordered w-100" id="invoices_due">
<thead> <thead>
<tr> <tr>
@ -20,7 +20,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($o->invoices->where('due','>',0) as $oo) @foreach ($x as $oo)
<tr @if ($oo->due_date->isPast()) class="table-danger" @endif> <tr @if ($oo->due_date->isPast()) class="table-danger" @endif>
<td>{{ $oo->account->name }}</td> <td>{{ $oo->account->name }}</td>
<td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->sid }}</a></td> <td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->sid }}</a></td>

View File

@ -5,7 +5,7 @@
</div> </div>
<div class="card-body"> <div class="card-body">
@if($o->invoices->where('date_orig','>',($x=\Carbon\Carbon::now()->subMonths(12)))->where('due','=',0)->count()) @if(($x=$o->invoices()->where('ab_invoice.date_orig','>',\Carbon\Carbon::now()->subMonths(12)->unix())->with(['items.taxes','paymentitems.payment','account.country.currency'])->get()->where('due','<=',0))->count())
<table class="table table-bordered w-100" id="invoices_past"> <table class="table table-bordered w-100" id="invoices_past">
<thead> <thead>
<tr> <tr>
@ -19,7 +19,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($o->invoices->where('date_orig','>',$x)->where('due','=',0) as $oo) @foreach ($x as $oo)
<tr> <tr>
<td>{{ $oo->account->name }}</td> <td>{{ $oo->account->name }}</td>
<td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->sid }}</a></td> <td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->sid }}</a></td>

View File

@ -5,7 +5,7 @@
</div> </div>
<div class="card-body"> <div class="card-body">
@if($o->payments->where('date_orig','>',($x=\Carbon\Carbon::now()->subMonths(12)))->count()) @if(($x=$o->payments()->where('ab_payment.date_orig','>',\Carbon\Carbon::now()->subMonths(12)->unix())->with(['items','account'])->get())->count())
<table class="table table-bordered w-100" id="payments_past"> <table class="table table-bordered w-100" id="payments_past">
<thead> <thead>
<tr> <tr>
@ -19,7 +19,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($o->payments->where('date_orig','>',($x=\Carbon\Carbon::now()->subMonths(12))) as $oo) @foreach ($x as $oo)
<tr> <tr>
<td>{{ $oo->account->name }}</td> <td>{{ $oo->account->name }}</td>
<td>{{ $oo->sid }}</td> <td>{{ $oo->sid }}</td>