Skip to content

Commit f02b3b6

Browse files
author
Jose Ganora
committed
#WN-114# changes to filter applications by filtered logs
1 parent 161dc00 commit f02b3b6

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

app/Classes/Repositories/ApplicationRepository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

app/Classes/Repositories/ApplicationRepositoryInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

app/Http/Controllers/UsageLogController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)