Skip to content

Commit

Permalink
fixed n+1
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Jun 4, 2021
1 parent 434bd14 commit a42429b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Banking/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Accounts extends Controller
*/
public function index()
{
$accounts = Account::collect();
$accounts = Account::with('income_transactions', 'expense_transactions')->collect();

return $this->response('banking.accounts.index', compact('accounts'));
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Banking/Reconciliations.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected function getTransactions($account, $started_at, $ended_at)
$started = explode(' ', $started_at)[0] . ' 00:00:00';
$ended = explode(' ', $ended_at)[0] . ' 23:59:59';

$transactions = Transaction::where('account_id', $account->id)->whereBetween('paid_at', [$started, $ended])->get();
$transactions = Transaction::with('account', 'contact')->where('account_id', $account->id)->whereBetween('paid_at', [$started, $ended])->get();

return collect($transactions)->sortByDesc('paid_at');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Purchases/Vendors.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function show(Contact $vendor)
}

// Handle payments
$transactions = Transaction::with('category')->where('contact_id', $vendor->id)->expense()->get();
$transactions = Transaction::with('account', 'category')->where('contact_id', $vendor->id)->expense()->get();

$counts['transactions'] = $transactions->count();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Sales/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function show(Contact $customer)
}

// Handle transactions
$transactions = Transaction::with('category')->where('contact_id', $customer->id)->income()->get();
$transactions = Transaction::with('account', 'category')->where('contact_id', $customer->id)->income()->get();

$counts['transactions'] = $transactions->count();

Expand Down

0 comments on commit a42429b

Please sign in to comment.