Improve query efficiency

This commit is contained in:
David Bomba 2021-10-08 16:03:26 +11:00
parent 9c18ab7230
commit e6be94ad22
5 changed files with 15 additions and 7 deletions

View File

@ -216,7 +216,7 @@ class PreviewController extends BaseController
if(!$request->has('entity_id'))
$entity_obj->service()->fillDefaults()->save();
$entity_obj->load('client');
$entity_obj->load('client.contacts','company');
App::forgetInstance('translator');
$t = app('translator');

View File

@ -74,12 +74,15 @@ class EmailPayment implements ShouldQueue
MultiDB::setDb($this->company->db);
$this->payment->load('invoices');
$this->contact->load('client');
$email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build();
$invitation = null;
if($this->payment->invoices()->exists())
$invitation = $this->payment->invoices()->first()->invitations()->first();
if($this->payment->invoices && $this->payment->invoices->count() >=1)
$invitation = $this->payment->invoices->first()->invitations()->first();
$nmo = new NinjaMailerObject;
$nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation);

View File

@ -47,6 +47,7 @@ class PaymentEmailEngine extends BaseEmailEngine
$this->company = $payment->company;
$this->client = $payment->client;
$this->contact = $contact ?: $this->client->primary_contact()->first();
$this->contact->load('client.company');
$this->settings = $this->client->getMergedSettings();
$this->template_data = $template_data;
$this->helpers = new Helpers();

View File

@ -84,12 +84,12 @@ class Client extends BaseModel implements HasLocalePreference
];
protected $with = [
'gateway_tokens',
'documents',
'contacts.company',
// 'gateway_tokens',
// 'documents',
// 'contacts.company',
// 'currency',
// 'primary_contact',
'country',
// 'country',
// 'contacts',
// 'shipping_country',
// 'company',

View File

@ -64,6 +64,10 @@ class Subscription extends BaseModel
'deleted_at' => 'timestamp',
];
protected $with = [
'company',
];
public function service(): SubscriptionService
{
return new SubscriptionService($this);