Skip to content

Commit

Permalink
Performance improvements for eager loading (invoiceninja#3584)
Browse files Browse the repository at this point in the history
* Fixes for Sentry

* performance improvements for eager loading
  • Loading branch information
turbo124 authored Apr 2, 2020
1 parent f99a898 commit cfafd65
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 69 deletions.
9 changes: 5 additions & 4 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ public function report(Exception $exception)

app('sentry')->configureScope(function (Scope $scope): void {

if(auth()->guard('contact')->user() && auth()->guard('contact')->user()->account->report_errors) {
if(auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) {
$scope->setUser([
'id' => auth()->guard('contact')->user()->account->key,
'id' => auth()->guard('contact')->user()->company->account->key,
'email' => "[email protected]",
'name' => "Anonymous User",
]);
}
else if (auth()->user() && auth()->user()->account->report_errors) {
}
else if (auth()->guard('user')->user() && auth()->user()->company()->account->report_errors) {
$scope->setUser([
'id' => auth()->user()->account->key,
'email' => "[email protected]",
'name' => "Anonymous User",
]);
}


});

app('sentry')->captureException($exception);
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ public function apiLogin(Request $request)

$user->setCompany($user->company_user->account->default_company);

$ct = CompanyUser::whereUserId($user->id)->with('company');
// $ct = CompanyUser::whereUserId($user->id)->with('company');
$ct = CompanyUser::whereUserId($user->id);

return $this->listResponse($ct);

} else {
$this->incrementLoginAttempts($request);

Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ private function buildManager()
$include = implode(",", $this->forced_includes);
}

\Log::error(print_r($include,1));

$this->manager->parseIncludes($include);

$this->serializer = request()->input('serializer') ?: EntityTransformer::API_SERIALIZER_ARRAY;
Expand Down Expand Up @@ -256,10 +258,10 @@ protected function getRequestIncludes($data)
'company.company_gateways.gateway',
'company.clients.contacts',
'company.products',
'company.invoices',
'company.invoices.invitations.company',
'company.payments.paymentables',
'company.quotes',
'company.credits',
'company.quotes.invitations.company',
'company.credits.invitations.company',
'company.vendors.contacts',
'company.expenses',
'company.tasks',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ClientPortal/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private function makePayment(array $ids)

$invoices->map(function ($invoice) {
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client);
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
//$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
return $invoice;
});

Expand Down
20 changes: 19 additions & 1 deletion app/Http/Controllers/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function doSetup(StoreSetupRequest $request)
return back(); // This should never be reached.
}

$mail_driver = $request->input('mail_driver');

if(!$this->failsafeMailCheck())
$mail_driver = 'log';

$_ENV['APP_KEY'] = config('app.key');
$_ENV['APP_URL'] = $request->input('url');
$_ENV['APP_DEBUG'] = $request->input('debug') ? 'true' : 'false';
Expand All @@ -54,7 +59,7 @@ public function doSetup(StoreSetupRequest $request)
$_ENV['DB_DATABASE1'] = $request->input('database');
$_ENV['DB_USERNAME1'] = $request->input('db_username');
$_ENV['DB_PASSWORD1'] = $request->input('db_password');
$_ENV['MAIL_DRIVER'] = $request->input('mail_driver');
$_ENV['MAIL_DRIVER'] = $mail_driver;
$_ENV['MAIL_PORT'] = $request->input('mail_port');
$_ENV['MAIL_ENCRYPTION'] = $request->input('encryption');
$_ENV['MAIL_HOST'] = $request->input('mail_host');
Expand Down Expand Up @@ -154,4 +159,17 @@ public function checkMail(CheckMailRequest $request)
return response()->json(['message' => $e->getMessage()], 400);
}
}

private function failsafeMailCheck($request)
{

$response_array = SystemHealth::testMailServer($request);

if($response_array instanceof Response)
return true;


return false;

}
}
45 changes: 0 additions & 45 deletions app/Http/ViewComposers/TranslationComposer.php

This file was deleted.

8 changes: 6 additions & 2 deletions app/Models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,17 @@ public function group_settings()
public function getCreditCardGateway() :?CompanyGateway
{
$company_gateways = $this->getSetting('company_gateway_ids');

if ($company_gateways) {

info($company_gateways);
info($this->company->id);
if (strlen($company_gateways)>=1) {
$gateways = $this->company->company_gateways->whereIn('id', $payment_gateways);
} else {
$gateways = $this->company->company_gateways;
}

\Log::error($gateways);

foreach ($gateways as $gateway) {
if (in_array(GatewayType::CREDIT_CARD, $gateway->driver($this)->gatewayTypes())) {
return $gateway;
Expand Down
10 changes: 0 additions & 10 deletions app/Providers/ComposerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ class ComposerServiceProvider extends ServiceProvider
public function boot()
{
view()->composer('portal.*', 'App\Http\ViewComposers\PortalComposer');

//view()->composer('*', 'App\Http\ViewComposers\HeaderComposer');
/*
view()->composer(
[
'client.edit',
],
'App\Http\ViewComposers\TranslationComposer'
);
*/
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Utils/Traits/Inviteable.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getLink() :string
$entity_type = strtolower(class_basename($this->entityType()));

//$this->with('company','contact',$this->entity_type);
$this->with('company');
//$this->with('company');

$domain = isset($this->company->portal_domain) ?: $this->company->domain();

Expand Down
2 changes: 1 addition & 1 deletion resources/views/portal/ninja2020/invoices/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class="align-middle inline-block min-w-full shadow overflow-hidden rounded borde
{{ $invoice->number }}
</td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
{{ $invoice->formatDate($invoice->date, $invoice->client->date_format()) }}
{{ $invoice->due_date }} <!-- $invoice->formatDate($invoice->date, $invoice->client->date_format())-->
</td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
{{ App\Utils\Number::formatMoney($invoice->balance, $invoice->client) }}
Expand Down

0 comments on commit cfafd65

Please sign in to comment.