File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ public function allDesc($columns = ['*'])
4242 return $ this ->applicationModel ->orderBy ('id ' , 'desc ' )->get ($ columns );
4343 }
4444
45+ public function findIn ($ ids = [], $ columns = ['* ' ])
46+ {
47+ return $ this ->applicationModel ->whereIn ('id ' , $ ids )->get ($ columns );
48+ }
49+
4550 /**
4651 * @param array $attributes
4752 * @return Application
Original file line number Diff line number Diff line change @@ -14,4 +14,6 @@ interface ApplicationRepositoryInterface extends RepositoryInterface
1414 public function findForUserId ($ tenantId , $ userId );
1515
1616 public function allDesc ($ columns );
17+
18+ public function findIn ($ ids = [], $ columns = ['* ' ]);
1719}
Original file line number Diff line number Diff line change @@ -235,21 +235,22 @@ public function getTotals(Request $request)
235235 }
236236 $ usageLogs = $ query ->get ();
237237
238- $ applications = $ this ->applicationRepo ->all ();
238+ $ uniqueApplicationIds = $ usageLogs ->pluck ('application_id ' )->unique ();
239+
240+ $ applications = $ this ->applicationRepo ->findIn ($ uniqueApplicationIds ->toArray ());
239241
240242 // Calculate total estimated users
241243 $ totalEstimatedUsers = $ applications ->map (function ($ application ) {
242244 return $ application ->estimated_users_count ;
243245 })->sum ();
244246
245247 $ totals = [
246- 'applications ' => count ($ applications ),
248+ 'applications ' => count ($ uniqueApplicationIds ),
247249 'estimatedUsers ' => $ totalEstimatedUsers ,
248250 'hits ' => count ($ usageLogs ),
249251 ];
250252 } catch (\Exception $ e ) {
251253 Log::error ('Could not get Usage Log totals ' , ['message ' => $ e ->getMessage ()]);
252-
253254 return response ()->json ([
254255 'status ' => 500 ,
255256 'error_message ' => 'Could not get Usage Log totals ' ,
You can’t perform that action at this time.
0 commit comments