From 8696acf4d32e886c23a07ed0daf85cfe9a2f6d07 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 1 Sep 2016 20:02:37 +0300 Subject: [PATCH] Reduce extra queries --- app/Http/Middleware/QueryLogging.php | 1 + app/Libraries/HistoryUtils.php | 3 ++- app/Ninja/Repositories/DashboardRepository.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 42bf47288975..57a26166a127 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -33,6 +33,7 @@ class QueryLogging $queries = DB::getQueryLog(); $count = count($queries); Log::info($request->method() . ' - ' . $request->url() . ": $count queries"); + //Log::info($queries); } } diff --git a/app/Libraries/HistoryUtils.php b/app/Libraries/HistoryUtils.php index ac2577d3a0d6..ade383ff5e2a 100644 --- a/app/Libraries/HistoryUtils.php +++ b/app/Libraries/HistoryUtils.php @@ -33,7 +33,7 @@ class HistoryUtils ]; $activities = Activity::scope() - ->with('client.contacts', 'invoice') + ->with(['client.contacts', 'invoice']) ->whereIn('user_id', $userIds) ->whereIn('activity_type_id', $activityTypes) ->orderBy('id', 'asc') @@ -46,6 +46,7 @@ class HistoryUtils $entity = $activity->client; } else { $entity = $activity->invoice; + $entity->setRelation('client', $activity->client); } static::trackViewed($entity); diff --git a/app/Ninja/Repositories/DashboardRepository.php b/app/Ninja/Repositories/DashboardRepository.php index 47046ffc091d..5da859f2867d 100644 --- a/app/Ninja/Repositories/DashboardRepository.php +++ b/app/Ninja/Repositories/DashboardRepository.php @@ -114,7 +114,7 @@ class DashboardRepository } return $activities->orderBy('activities.created_at', 'desc') - ->with('client.contacts', 'user', 'invoice', 'payment', 'credit', 'account') + ->with('client.contacts', 'user', 'invoice', 'payment', 'credit', 'account', 'task') ->take(50) ->get(); }