1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for eager loading with multiple groups

This commit is contained in:
David Bomba 2021-09-04 17:28:08 +10:00
parent fa635a7ef0
commit 32dc4554c2
3 changed files with 45 additions and 4 deletions

View File

@ -24,6 +24,7 @@ use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\Country;
use App\Models\Credit;
use App\Models\Document;
use App\Models\Expense;
use App\Models\Product;
use App\Models\Project;
@ -230,6 +231,7 @@ class CreateTestData extends Command
'company_id' => $company->id,
]);
$this->count = $this->count * 10;
$this->info('Creating '.$this->count.' clients');
@ -387,6 +389,14 @@ class CreateTestData extends Command
'company_id' => $company->id,
]);
Document::factory()->count(50)->create([
'user_id' => $user->id,
'company_id' => $company->id,
'documentable_type' => Client::class,
'documentable_id' => $client->id
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
@ -428,6 +438,13 @@ class CreateTestData extends Command
'company_id' => $client->company->id,
]);
Document::factory()->count(50)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Vendor::class,
'documentable_id' => $vendor->id
]);
VendorContact::factory()->create([
'user_id' => $client->user->id,
'vendor_id' => $vendor->id,
@ -449,6 +466,14 @@ class CreateTestData extends Command
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Task::class,
'documentable_id' => $vendor->id
]);
}
private function createProject($client)
@ -457,6 +482,13 @@ class CreateTestData extends Command
'user_id' => $client->user->id,
'company_id' => $client->company->id,
]);
Document::factory()->count(5)->create([
'user_id' => $client->user->id,
'company_id' => $client->company_id,
'documentable_type' => Project::class,
'documentable_id' => $vendor->id
]);
}
private function createInvoice($client)
@ -506,6 +538,13 @@ class CreateTestData extends Command
$invoice = $invoice->service()->markPaid()->save();
}
Document::factory()->count(5)->create([
'user_id' => $invoice->user->id,
'company_id' => $invoice->company_id,
'documentable_type' => Invoice::class,
'documentable_id' => $invoice->id
]);
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
}

View File

@ -216,7 +216,7 @@ class BaseController extends Controller
$query->whereNotNull('updated_at')->with('documents');
},
'company.clients' => function ($query) use ($updated_at, $user) {
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens', 'documents');
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts.company', 'gateway_tokens', 'documents', 'group_settings');
if(!$user->hasPermission('view_client'))
$query->where('clients.user_id', $user->id)->orWhere('clients.assigned_user_id', $user->id);
@ -457,7 +457,7 @@ class BaseController extends Controller
$query->whereNotNull('created_at')->with('documents');
},
'company.clients' => function ($query) use ($created_at, $user) {
$query->where('clients.created_at', '>=', $created_at)->with('contacts.company', 'gateway_tokens', 'documents');
$query->where('clients.created_at', '>=', $created_at)->with('contacts.company', 'gateway_tokens', 'documents', 'group_settings');
if(!$user->hasPermission('view_client'))
$query->where('clients.user_id', $user->id)->orWhere('clients.assigned_user_id', $user->id);

View File

@ -52,8 +52,10 @@ class QueryLogging
$timeEnd = microtime(true);
$time = $timeEnd - $timeStart;
// if($count > 150)
// nlog($queries);
nlog("Query count = {$count}");
//if($count > 250)
nlog($queries);
$ip = '';