From b1cb9259da2bd4cf709a06b58d75258f0a664fb0 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 May 2024 18:01:47 +0100 Subject: [PATCH] Re-use total to avoid duplicate count Signed-off-by: snipe --- app/Http/Controllers/Api/ReportsController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php index fbeb78fc8f..8761c9442b 100644 --- a/app/Http/Controllers/Api/ReportsController.php +++ b/app/Http/Controllers/Api/ReportsController.php @@ -78,13 +78,14 @@ class ReportsController extends Controller ]; + $total = $actionlogs->count(); // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $actionlogs->count()) ? $actionlogs->count() : app('api_offset_value'); + $offset = ($request->input('offset') > $total) ? $total : app('api_offset_value'); $limit = app('api_limit_value'); $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $order = ($request->input('order') == 'asc') ? 'asc' : 'desc'; - $total = $actionlogs->count(); + $actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get();