mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-05 02:14:35 -04:00
Improve N+1 queries
This commit is contained in:
parent
61f09e1ad4
commit
094d43be4f
@ -34,7 +34,7 @@ class GmailTransport extends AbstractTransport
|
|||||||
$message = MessageConverter::toEmail($message->getOriginalMessage());
|
$message = MessageConverter::toEmail($message->getOriginalMessage());
|
||||||
|
|
||||||
/** @phpstan-ignore-next-line **/
|
/** @phpstan-ignore-next-line **/
|
||||||
$token = $message->getHeaders()->get('gmailtoken')->getValue();
|
$token = $message->getHeaders()->get('gmailtoken')->getValue(); // @phpstan-ignore-line
|
||||||
$message->getHeaders()->remove('gmailtoken');
|
$message->getHeaders()->remove('gmailtoken');
|
||||||
|
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
@ -53,9 +53,8 @@ class GmailTransport extends AbstractTransport
|
|||||||
if ($bccs) {
|
if ($bccs) {
|
||||||
$bcc_list = 'Bcc: ';
|
$bcc_list = 'Bcc: ';
|
||||||
|
|
||||||
|
|
||||||
/** @phpstan-ignore-next-line **/
|
|
||||||
foreach ($bccs->getAddresses() as $address) {
|
foreach ($bccs->getAddresses() as $address) {
|
||||||
|
|
||||||
$bcc_list .= $address->getAddress() .',';
|
$bcc_list .= $address->getAddress() .',';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,10 @@ class CheckClientExistence
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']); // @phpstan-ignore method.notFound
|
||||||
|
|
||||||
$multiple_contacts = ClientContact::query()
|
$multiple_contacts = ClientContact::query()
|
||||||
->with('client.gateway_tokens', 'company')
|
// ->with('client.gateway_tokens', 'company')
|
||||||
->where('email', auth()->guard('contact')->user()->email)
|
->where('email', auth()->guard('contact')->user()->email)
|
||||||
->whereNotNull('email')
|
->whereNotNull('email')
|
||||||
->where('email', '<>', '')
|
->where('email', '<>', '')
|
||||||
@ -56,6 +58,11 @@ class CheckClientExistence
|
|||||||
|
|
||||||
if (count($multiple_contacts) == 1 && ! Auth::guard('contact')->check()) {
|
if (count($multiple_contacts) == 1 && ! Auth::guard('contact')->check()) {
|
||||||
Auth::guard('contact')->loginUsingId($multiple_contacts[0]->id, true);
|
Auth::guard('contact')->loginUsingId($multiple_contacts[0]->id, true);
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
||||||
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session()->put('multiple_contacts', $multiple_contacts);
|
session()->put('multiple_contacts', $multiple_contacts);
|
||||||
|
@ -25,10 +25,12 @@ class ClientPortalEnabled
|
|||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
/** @var \App\Models\ClientContact $client_contact */
|
|
||||||
$client_contact = auth()->user();
|
|
||||||
|
|
||||||
if ($client_contact->client->getSetting('enable_client_portal') === false) {
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
||||||
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
|
if (auth()->guard('contact')->user()->client->getSetting('enable_client_portal') === false) {
|
||||||
return redirect()->route('client.error')->with(['title' => ctrans('texts.client_portal'), 'notification' => 'This section of the app has been disabled by the administrator.']);
|
return redirect()->route('client.error')->with(['title' => ctrans('texts.client_portal'), 'notification' => 'This section of the app has been disabled by the administrator.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,15 +69,23 @@ class Locale
|
|||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/*LOCALE SET */
|
/*LOCALE SET */
|
||||||
if ($request->has('lang') && in_array($request->input('lang', 'en'), $this->locales)) {
|
if ($request->has('lang') && in_array($request->input('lang', 'en'), $this->locales)) {
|
||||||
$locale = $request->input('lang');
|
$locale = $request->input('lang');
|
||||||
App::setLocale($locale);
|
App::setLocale($locale);
|
||||||
} elseif (auth()->guard('contact')->user()) {
|
} elseif (auth()->guard('contact')->user()) {
|
||||||
App::setLocale(auth()->guard('contact')->user()->client()->setEagerLoads([])->first()->locale());
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) { // @phpstan-ignore method.undefined
|
||||||
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
|
App::setLocale(auth()->guard('contact')->user()->client->locale());
|
||||||
} elseif (auth()->user()) {
|
} elseif (auth()->user()) {
|
||||||
try {
|
try {
|
||||||
App::setLocale(auth()->user()->company()->getLocale());
|
App::setLocale(auth()->user()->company()->getLocale()); // @phpstan-ignore method.undefined
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,6 +14,8 @@ class ShowCreditRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return ! $this->credit->is_deleted
|
return ! $this->credit->is_deleted
|
||||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS
|
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS
|
||||||
&& auth()->guard('contact')->user()->client_id === $this->credit->client_id;
|
&& auth()->guard('contact')->user()->client_id === $this->credit->client_id;
|
||||||
|
@ -19,6 +19,9 @@ class ProcessInvoicesInBulkRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ class ShowInvoiceRequest extends Request
|
|||||||
*/
|
*/
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return (int) auth()->guard('contact')->user()->client_id === (int) $this->invoice->client_id
|
return (int) auth()->guard('contact')->user()->client_id === (int) $this->invoice->client_id
|
||||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ class ShowInvoicesRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,11 @@ class CreatePaymentMethodRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
||||||
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
/** @var Client $client */
|
/** @var Client $client */
|
||||||
$client = auth()->guard('contact')->user()->client;
|
$client = auth()->guard('contact')->user()->client;
|
||||||
|
|
||||||
|
@ -15,6 +15,13 @@ class StorePrePaymentRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
||||||
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,9 @@ class ProcessQuotesInBulkRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,9 @@ class ShowQuoteRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->client->id === (int) $this->quote->client_id
|
return auth()->guard('contact')->user()->client->id === (int) $this->quote->client_id
|
||||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ class ShowQuotesRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,9 @@ class RequestCancellationRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ class ShowRecurringInvoiceRequest extends Request
|
|||||||
{
|
{
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->client->id == $this->recurring_invoice->client_id
|
return auth()->guard('contact')->user()->client->id == $this->recurring_invoice->client_id
|
||||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ class ShowRecurringInvoicesRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||||
|
|
||||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,11 @@ class ShowTasksRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
||||||
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
return (bool) auth()->guard('contact')->user()->client->getSetting('enable_client_portal_tasks');
|
return (bool) auth()->guard('contact')->user()->client->getSetting('enable_client_portal_tasks');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,12 @@ class StoreUploadRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line **/
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
||||||
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
return (bool) auth()->guard('contact')->user()->client->getSetting('client_portal_enable_uploads');
|
return (bool) auth()->guard('contact')->user()->client->getSetting('client_portal_enable_uploads');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,10 @@ class PortalComposer
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
||||||
|
$query->without('gateway_tokens', 'documents'); // Exclude 'grandchildren' relation of 'client'
|
||||||
|
}]);
|
||||||
|
|
||||||
$this->settings = auth()->guard('contact')->user()->client->getMergedSettings();
|
$this->settings = auth()->guard('contact')->user()->client->getMergedSettings();
|
||||||
|
|
||||||
$data['sidebar'] = $this->sidebarMenu();
|
$data['sidebar'] = $this->sidebarMenu();
|
||||||
|
@ -41,6 +41,7 @@ class RecurringInvoicesTable extends Component
|
|||||||
$query = RecurringInvoice::query();
|
$query = RecurringInvoice::query();
|
||||||
|
|
||||||
$query = $query
|
$query = $query
|
||||||
|
// ->with('client')
|
||||||
->where('client_id', auth()->guard('contact')->user()->client_id)
|
->where('client_id', auth()->guard('contact')->user()->client_id)
|
||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE])
|
->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE])
|
||||||
|
@ -29,3 +29,4 @@ parameters:
|
|||||||
- '#makeHidden#'
|
- '#makeHidden#'
|
||||||
- '#Socialite#'
|
- '#Socialite#'
|
||||||
- '#Access to protected property#'
|
- '#Access to protected property#'
|
||||||
|
- '#Call to undefined method .*#'
|
Loading…
x
Reference in New Issue
Block a user