Query optimisations using with()
This commit is contained in:
parent
cd18b98859
commit
f41fc3eb9c
60
app/Console/Commands/ServiceList.php
Normal file
60
app/Console/Commands/ServiceList.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
use App\Models\Service;
|
||||||
|
|
||||||
|
class ServiceList extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'service:list';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'List all services';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
DB::listen(function($query) {
|
||||||
|
Log::debug('- SQL',['sql'=>$query->sql,'binding'=>$query->bindings]);
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (Service::active()->get() as $o) {
|
||||||
|
$this->info(sprintf('|%10s|%-6s|%-20s|%-50s|%8s|%14s|%10s|',
|
||||||
|
$o->sid,
|
||||||
|
$o->product->category,
|
||||||
|
$o->product_name,
|
||||||
|
$o->name_short,
|
||||||
|
$o->active ? 'active' : 'inactive',
|
||||||
|
$o->status,
|
||||||
|
$o->invoice_next ? $o->invoice_next : NULL,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,6 @@ class Invoice extends Model
|
|||||||
{
|
{
|
||||||
protected $table = 'ab_invoice';
|
protected $table = 'ab_invoice';
|
||||||
protected $dates = ['date_orig','due_date'];
|
protected $dates = ['date_orig','due_date'];
|
||||||
protected $with = ['account.country.currency','items.taxes','paymentitems'];
|
|
||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
'date_due',
|
'date_due',
|
||||||
@ -25,6 +24,12 @@ class Invoice extends Model
|
|||||||
'total',
|
'total',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $with = [
|
||||||
|
'account.country.currency',
|
||||||
|
'items.taxes',
|
||||||
|
'paymentitems'
|
||||||
|
];
|
||||||
|
|
||||||
private $_total = 0;
|
private $_total = 0;
|
||||||
private $_total_tax = 0;
|
private $_total_tax = 0;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ class InvoiceItem extends Model
|
|||||||
{
|
{
|
||||||
protected $dates = ['date_start','date_stop'];
|
protected $dates = ['date_start','date_stop'];
|
||||||
public $dateFormat = 'U';
|
public $dateFormat = 'U';
|
||||||
|
|
||||||
protected $table = 'ab_invoice_item';
|
protected $table = 'ab_invoice_item';
|
||||||
|
|
||||||
private $_tax = 0;
|
private $_tax = 0;
|
||||||
|
@ -24,20 +24,6 @@ class Service extends Model
|
|||||||
const CREATED_AT = 'date_orig';
|
const CREATED_AT = 'date_orig';
|
||||||
const UPDATED_AT = 'date_last';
|
const UPDATED_AT = 'date_last';
|
||||||
|
|
||||||
protected $dates = [
|
|
||||||
'date_last_invoice',
|
|
||||||
'date_next_invoice'.
|
|
||||||
'date_start',
|
|
||||||
'date_end',
|
|
||||||
];
|
|
||||||
|
|
||||||
public $dateFormat = 'U';
|
|
||||||
protected $table = 'ab_service';
|
|
||||||
|
|
||||||
protected $casts = [
|
|
||||||
'order_info'=>'array',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
'account_name',
|
'account_name',
|
||||||
'admin_service_id_url',
|
'admin_service_id_url',
|
||||||
@ -51,6 +37,20 @@ class Service extends Model
|
|||||||
'status',
|
'status',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'order_info'=>'array',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $dates = [
|
||||||
|
'date_last_invoice',
|
||||||
|
'date_next_invoice'.
|
||||||
|
'date_start',
|
||||||
|
'date_end',
|
||||||
|
];
|
||||||
|
public $dateFormat = 'U';
|
||||||
|
|
||||||
|
protected $table = 'ab_service';
|
||||||
|
|
||||||
protected $visible = [
|
protected $visible = [
|
||||||
'account_name',
|
'account_name',
|
||||||
'admin_service_id_url',
|
'admin_service_id_url',
|
||||||
@ -67,6 +67,14 @@ class Service extends Model
|
|||||||
'status',
|
'status',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $with = [
|
||||||
|
'account.language',
|
||||||
|
'charges',
|
||||||
|
'invoice_items',
|
||||||
|
'product',
|
||||||
|
'type',
|
||||||
|
];
|
||||||
|
|
||||||
private $inactive_status = [
|
private $inactive_status = [
|
||||||
'CANCELLED',
|
'CANCELLED',
|
||||||
'ORDER-REJECTED',
|
'ORDER-REJECTED',
|
||||||
|
@ -7,10 +7,10 @@ use App\Traits\NextKey;
|
|||||||
class Domain extends \App\Models\Base\ServiceType
|
class Domain extends \App\Models\Base\ServiceType
|
||||||
{
|
{
|
||||||
use NextKey;
|
use NextKey;
|
||||||
|
|
||||||
const RECORD_ID = 'service__domain';
|
const RECORD_ID = 'service__domain';
|
||||||
|
|
||||||
protected $table = 'ab_service__domain';
|
protected $table = 'ab_service__domain';
|
||||||
|
protected $with = ['tld'];
|
||||||
|
|
||||||
public function tld()
|
public function tld()
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,6 @@ use App\Traits\NextKey;
|
|||||||
class Host extends \App\Models\Base\ServiceType
|
class Host extends \App\Models\Base\ServiceType
|
||||||
{
|
{
|
||||||
use NextKey;
|
use NextKey;
|
||||||
|
|
||||||
const RECORD_ID = 'service__hosting';
|
const RECORD_ID = 'service__hosting';
|
||||||
|
|
||||||
protected $table = 'ab_service__hosting';
|
protected $table = 'ab_service__hosting';
|
||||||
|
@ -7,7 +7,6 @@ use App\Traits\NextKey;
|
|||||||
class SSL extends \App\Models\Base\ServiceType
|
class SSL extends \App\Models\Base\ServiceType
|
||||||
{
|
{
|
||||||
use NextKey;
|
use NextKey;
|
||||||
|
|
||||||
const RECORD_ID = 'service__ssl';
|
const RECORD_ID = 'service__ssl';
|
||||||
|
|
||||||
protected $table = 'ab_service__ssl';
|
protected $table = 'ab_service__ssl';
|
||||||
|
26
app/User.php
26
app/User.php
@ -19,6 +19,14 @@ class User extends Authenticatable
|
|||||||
{
|
{
|
||||||
use HasApiTokens,Notifiable,UserSwitch,HasQuickBooksToken;
|
use HasApiTokens,Notifiable,UserSwitch,HasQuickBooksToken;
|
||||||
|
|
||||||
|
protected $appends = [
|
||||||
|
'active_display',
|
||||||
|
'services_count_html',
|
||||||
|
'surfirstname',
|
||||||
|
'switch_url',
|
||||||
|
'user_id_url',
|
||||||
|
];
|
||||||
|
|
||||||
protected $dates = [
|
protected $dates = [
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
@ -44,14 +52,6 @@ class User extends Authenticatable
|
|||||||
'remember_token',
|
'remember_token',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $appends = [
|
|
||||||
'active_display',
|
|
||||||
'services_count_html',
|
|
||||||
'surfirstname',
|
|
||||||
'switch_url',
|
|
||||||
'user_id_url',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $visible = [
|
protected $visible = [
|
||||||
'active_display',
|
'active_display',
|
||||||
'id',
|
'id',
|
||||||
@ -62,6 +62,8 @@ class User extends Authenticatable
|
|||||||
'user_id_url',
|
'user_id_url',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $with = ['accounts'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The accounts that this user manages
|
* The accounts that this user manages
|
||||||
*
|
*
|
||||||
@ -129,8 +131,7 @@ class User extends Authenticatable
|
|||||||
*/
|
*/
|
||||||
public function services()
|
public function services()
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough(Models\Service::class,Models\Account::class)
|
return $this->hasManyThrough(Models\Service::class,Models\Account::class);
|
||||||
->with(['account','product','invoices.items.tax','type']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -359,7 +360,6 @@ class User extends Authenticatable
|
|||||||
{
|
{
|
||||||
$result = new DatabaseCollection();
|
$result = new DatabaseCollection();
|
||||||
$clients = $this->all_clients();
|
$clients = $this->all_clients();
|
||||||
$clients->load('accounts');
|
|
||||||
|
|
||||||
foreach ($clients->pluck('accounts') as $accounts) {
|
foreach ($clients->pluck('accounts') as $accounts) {
|
||||||
foreach ($accounts as $o) {
|
foreach ($accounts as $o) {
|
||||||
@ -480,10 +480,6 @@ class User extends Authenticatable
|
|||||||
public function next_invoice_items(bool $future=FALSE): DatabaseCollection
|
public function next_invoice_items(bool $future=FALSE): DatabaseCollection
|
||||||
{
|
{
|
||||||
$result = new DatabaseCollection;
|
$result = new DatabaseCollection;
|
||||||
$this->load([
|
|
||||||
'services.charges',
|
|
||||||
'services.invoice_items'
|
|
||||||
]);
|
|
||||||
|
|
||||||
foreach ($this->services as $o) {
|
foreach ($this->services as $o) {
|
||||||
if ($future) {
|
if ($future) {
|
||||||
|
Loading…
Reference in New Issue
Block a user