mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Added relationLoaded checks to optimize queries
This commit is contained in:
parent
7744c6c41c
commit
2a5de605dc
@ -9,7 +9,7 @@ class ClientRequest extends EntityRequest {
|
||||
$client = parent::entity();
|
||||
|
||||
// eager load the contacts
|
||||
if ($client && ! count($client->contacts)) {
|
||||
if ($client && ! $client->relationLoaded('contacts')) {
|
||||
$client->load('contacts');
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,11 @@ class ExpenseRequest extends EntityRequest {
|
||||
{
|
||||
$expense = parent::entity();
|
||||
|
||||
// eager load the contacts
|
||||
if ($expense && ! count($expense->documents)) {
|
||||
// eager load the documents
|
||||
if ($expense && ! $expense->relationLoaded('documents')) {
|
||||
$expense->load('documents');
|
||||
}
|
||||
|
||||
|
||||
return $expense;
|
||||
}
|
||||
}
|
@ -8,8 +8,8 @@ class InvoiceRequest extends EntityRequest {
|
||||
{
|
||||
$invoice = parent::entity();
|
||||
|
||||
// eager load the contacts
|
||||
if ($invoice && ! count($invoice->invoice_items)) {
|
||||
// eager load the invoice items
|
||||
if ($invoice && ! $invoice->relationLoaded('invoice_items')) {
|
||||
$invoice->load('invoice_items');
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ class VendorRequest extends EntityRequest {
|
||||
$vendor = parent::entity();
|
||||
|
||||
// eager load the contacts
|
||||
if ($vendor && ! count($vendor->vendor_contacts)) {
|
||||
if ($vendor && ! $vendor->relationLoaded('vendor_contacts')) {
|
||||
$vendor->load('vendor_contacts');
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,9 @@ class Account extends Eloquent
|
||||
|
||||
public function isGatewayConfigured($gatewayId = 0)
|
||||
{
|
||||
$this->load('account_gateways');
|
||||
if ( ! $this->relationLoaded('account_gateways')) {
|
||||
$this->load('account_gateways');
|
||||
}
|
||||
|
||||
if ($gatewayId) {
|
||||
return $this->getGatewayConfig($gatewayId) != false;
|
||||
@ -241,7 +243,7 @@ class Account extends Eloquent
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
$this->load('users');
|
||||
//$this->load('users');
|
||||
$user = $this->users()->first();
|
||||
|
||||
return $user->getDisplayName();
|
||||
|
@ -256,13 +256,17 @@ class Client extends EntityModel
|
||||
|
||||
public function getGatewayToken()
|
||||
{
|
||||
$this->account->load('account_gateways');
|
||||
$account = $this->account;
|
||||
|
||||
if ( ! $account->relationLoaded('account_gateways')) {
|
||||
$account->load('account_gateways');
|
||||
}
|
||||
|
||||
if (!count($this->account->account_gateways)) {
|
||||
if (!count($account->account_gateways)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$accountGateway = $this->account->getGatewayConfig(GATEWAY_STRIPE);
|
||||
$accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE);
|
||||
|
||||
if (!$accountGateway) {
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user