diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index ec1bb3fdecc9..99ff15054929 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -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())); } diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index d2f36f3159a3..188a16fb7ae6 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -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); diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index be61d3d4476b..f1bec7cc3c56 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -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 = '';