mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Performance improvements. (#3180)
* Fixes for missing company object in events * Cleanup client balancing code * Fixes for client balance * Fixes for missing company variable * Fix activity transformer to prevent multiple DB calls
This commit is contained in:
parent
ff7b62de51
commit
9790a841c4
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Events\Invoice;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
@ -26,13 +27,16 @@ class InvoiceWasPaid
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
public $company;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Invoice $invoice)
|
||||
public function __construct(Invoice $invoice, Company $company)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
$this->company = $company;
|
||||
}
|
||||
}
|
||||
|
@ -72,26 +72,10 @@ class BaseController extends Controller
|
||||
if(request()->has('first_load') && request()->input('first_load') == 'true')
|
||||
{
|
||||
|
||||
/* For very large accounts, we reduce the includes automatically */
|
||||
if(auth()->user()->getCompany()->clients->count() > 1000)
|
||||
{
|
||||
$include = [
|
||||
'account',
|
||||
'user.company_user',
|
||||
'token',
|
||||
'company.activities',
|
||||
'company.users.company_user',
|
||||
'company.tax_rates',
|
||||
'company.groups',
|
||||
'company.company_gateways.gateway',
|
||||
// 'company.clients',
|
||||
// 'company.products',
|
||||
// 'company.invoices',
|
||||
// 'company.payments',
|
||||
// 'company.quotes',
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$include = [
|
||||
'account',
|
||||
'user.company_user',
|
||||
@ -107,6 +91,27 @@ class BaseController extends Controller
|
||||
'company.payments',
|
||||
'company.quotes',
|
||||
];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$include = [
|
||||
'account',
|
||||
'user.company_user',
|
||||
'token',
|
||||
'company.activities',
|
||||
'company.users.company_user',
|
||||
'company.tax_rates',
|
||||
'company.groups',
|
||||
// 'company.company_gateways.gateway',
|
||||
// 'company.clients',
|
||||
// 'company.products',
|
||||
// 'company.invoices',
|
||||
// 'company.payments',
|
||||
// 'company.quotes',
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$include = array_merge($this->forced_includes, $include);
|
||||
@ -147,6 +152,7 @@ class BaseController extends Controller
|
||||
$this->manager->setSerializer(new ArraySerializer());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,8 +163,8 @@ class BaseController extends Controller
|
||||
{
|
||||
|
||||
return response()->json(['message' => '404 | Nothing to see here!'], 404)
|
||||
->header('X-Api-Version', config('ninja.api_version'))
|
||||
->header('X-App-Version', config('ninja.app_version'));
|
||||
->header('X-API-VERSION', config('ninja.api_version'))
|
||||
->header('X-APP-VERSION', config('ninja.app_version'));
|
||||
|
||||
}
|
||||
|
||||
@ -188,6 +194,7 @@ class BaseController extends Controller
|
||||
$transformer = new $this->entity_transformer(Input::get('serializer'));
|
||||
|
||||
$includes = $transformer->getDefaultIncludes();
|
||||
|
||||
$includes = $this->getRequestIncludes($includes);
|
||||
|
||||
$query->with($includes);
|
||||
|
@ -106,7 +106,7 @@ class ApplyPaymentToInvoice implements ShouldQueue
|
||||
if($this->invoice->balance == 0){
|
||||
$this->invoice->status_id = Invoice::STATUS_PAID;
|
||||
$this->invoice->save();
|
||||
event(new InvoiceWasPaid($this->invoice));
|
||||
event(new InvoiceWasPaid($this->invoice, $this->invoice->company));
|
||||
}
|
||||
elseif($this->payment->amount > 0 && $this->invoice->balance > 0)
|
||||
$this->invoice->status_id = Invoice::STATUS_PARTIAL;
|
||||
|
@ -36,7 +36,7 @@ class CreateInvoicePdf implements ShouldQueue
|
||||
|
||||
public $invoice;
|
||||
|
||||
|
||||
public $company;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
|
@ -414,7 +414,7 @@ class Invoice extends BaseModel
|
||||
if($this->balance == 0) {
|
||||
$this->status_id = self::STATUS_PAID;
|
||||
$this->save();
|
||||
event(new InvoiceWasPaid($this));
|
||||
event(new InvoiceWasPaid($this, $this->company));
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
protected $presenter = 'App\Models\Presenters\UserPresenter';
|
||||
|
||||
protected $with = ['companies'];
|
||||
protected $with = []; // ? companies also
|
||||
|
||||
protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||
|
||||
@ -105,7 +105,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return $this->encodePrimaryKey($this->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a account.
|
||||
*
|
||||
|
@ -27,17 +27,17 @@ class ActivityTransformer extends EntityTransformer
|
||||
return [
|
||||
'id' => (string) $this->encodePrimaryKey($activity->id),
|
||||
'activity_type_id' => (string) $activity->activity_type_id,
|
||||
'client_id' => $activity->client ? (string) $this->encodePrimaryKey($activity->client->id) : '',
|
||||
'company_id' => $activity->company ? (string) $this->encodePrimaryKey($activity->company->id) : '',
|
||||
'client_id' => $activity->client_id ? (string) $this->encodePrimaryKey($activity->client_id) : '',
|
||||
'company_id' => $activity->company_id ? (string) $this->encodePrimaryKey($activity->company_id) : '',
|
||||
'user_id' => (string) $this->encodePrimaryKey($activity->user_id),
|
||||
'invoice_id' => $activity->invoice ? (string) $this->encodePrimaryKey($activity->invoice->id) : '',
|
||||
'payment_id' => $activity->payment ? (string) $this->encodePrimaryKey($activity->payment->id) : '',
|
||||
'credit_id' => $activity->credit ? (string) $this->encodePrimaryKey($activity->credit->id) : '',
|
||||
'invoice_id' => $activity->invoice_id ? (string) $this->encodePrimaryKey($activity->invoice_id) : '',
|
||||
'payment_id' => $activity->payment_id ? (string) $this->encodePrimaryKey($activity->payment_id) : '',
|
||||
'credit_id' => $activity->credit_id ? (string) $this->encodePrimaryKey($activity->credit_id) : '',
|
||||
'updated_at' => $activity->updated_at,
|
||||
'expense_id' => $activity->expense_id ? (string) $this->encodePrimaryKey($activity->expense->id) : '',
|
||||
'expense_id' => $activity->expense_id ? (string) $this->encodePrimaryKey($activity->expense_id) : '',
|
||||
'is_system' => (bool) $activity->is_system,
|
||||
'contact_id' => $activity->contact_id ? (string) $this->encodePrimaryKey($activity->contact->id) : '',
|
||||
'task_id' => $activity->task_id ? (string) $this->encodePrimaryKey($activity->task->id) : '',
|
||||
'contact_id' => $activity->contact_id ? (string) $this->encodePrimaryKey($activity->contact_id) : '',
|
||||
'task_id' => $activity->task_id ? (string) $this->encodePrimaryKey($activity->task_id) : '',
|
||||
'notes' => $activity->notes ? (string) $activity->notes : '',
|
||||
'ip' => (string) $activity->ip,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user