mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01: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());
|
||||
|
||||
/** @phpstan-ignore-next-line **/
|
||||
$token = $message->getHeaders()->get('gmailtoken')->getValue();
|
||||
$token = $message->getHeaders()->get('gmailtoken')->getValue(); // @phpstan-ignore-line
|
||||
$message->getHeaders()->remove('gmailtoken');
|
||||
|
||||
$client = new Client();
|
||||
@ -53,9 +53,8 @@ class GmailTransport extends AbstractTransport
|
||||
if ($bccs) {
|
||||
$bcc_list = 'Bcc: ';
|
||||
|
||||
foreach ($bccs->getAddresses() as $address) {
|
||||
|
||||
/** @phpstan-ignore-next-line **/
|
||||
foreach ($bccs->getAddresses() as $address) {
|
||||
$bcc_list .= $address->getAddress() .',';
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,10 @@ class CheckClientExistence
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']); // @phpstan-ignore method.notFound
|
||||
|
||||
$multiple_contacts = ClientContact::query()
|
||||
->with('client.gateway_tokens', 'company')
|
||||
// ->with('client.gateway_tokens', 'company')
|
||||
->where('email', auth()->guard('contact')->user()->email)
|
||||
->whereNotNull('email')
|
||||
->where('email', '<>', '')
|
||||
@ -56,6 +58,11 @@ class CheckClientExistence
|
||||
|
||||
if (count($multiple_contacts) == 1 && ! Auth::guard('contact')->check()) {
|
||||
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);
|
||||
|
@ -25,10 +25,12 @@ class ClientPortalEnabled
|
||||
*/
|
||||
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.']);
|
||||
}
|
||||
|
||||
|
@ -69,15 +69,23 @@ class Locale
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
|
||||
/*LOCALE SET */
|
||||
if ($request->has('lang') && in_array($request->input('lang', 'en'), $this->locales)) {
|
||||
$locale = $request->input('lang');
|
||||
App::setLocale($locale);
|
||||
} 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()) {
|
||||
try {
|
||||
App::setLocale(auth()->user()->company()->getLocale());
|
||||
App::setLocale(auth()->user()->company()->getLocale()); // @phpstan-ignore method.undefined
|
||||
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
} else {
|
||||
|
@ -14,6 +14,8 @@ class ShowCreditRequest extends FormRequest
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return ! $this->credit->is_deleted
|
||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS
|
||||
&& auth()->guard('contact')->user()->client_id === $this->credit->client_id;
|
||||
|
@ -19,6 +19,9 @@ class ProcessInvoicesInBulkRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,9 @@ class ShowInvoiceRequest extends Request
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return (int) auth()->guard('contact')->user()->client_id === (int) $this->invoice->client_id
|
||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ class ShowInvoicesRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,11 @@ class CreatePaymentMethodRequest extends FormRequest
|
||||
*/
|
||||
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 */
|
||||
$client = auth()->guard('contact')->user()->client;
|
||||
|
||||
|
@ -15,6 +15,13 @@ class StorePrePaymentRequest extends FormRequest
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@ class ProcessQuotesInBulkRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,9 @@ class ShowQuoteRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->client->id === (int) $this->quote->client_id
|
||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ class ShowQuotesRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,9 @@ class RequestCancellationRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@ class ShowRecurringInvoiceRequest extends Request
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->client->id == $this->recurring_invoice->client_id
|
||||
&& auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ class ShowRecurringInvoicesRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
auth()->guard('contact')->user()->loadMissing(['company']);
|
||||
|
||||
return auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,11 @@ class ShowTasksRequest extends FormRequest
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,12 @@ class StoreUploadRequest extends FormRequest
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,10 @@ class PortalComposer
|
||||
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();
|
||||
|
||||
$data['sidebar'] = $this->sidebarMenu();
|
||||
|
@ -41,6 +41,7 @@ class RecurringInvoicesTable extends Component
|
||||
$query = RecurringInvoice::query();
|
||||
|
||||
$query = $query
|
||||
// ->with('client')
|
||||
->where('client_id', auth()->guard('contact')->user()->client_id)
|
||||
->where('company_id', $this->company->id)
|
||||
->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE])
|
||||
|
@ -29,3 +29,4 @@ parameters:
|
||||
- '#makeHidden#'
|
||||
- '#Socialite#'
|
||||
- '#Access to protected property#'
|
||||
- '#Call to undefined method .*#'
|
Loading…
Reference in New Issue
Block a user