Re-use total to avoid duplicate count

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-05-28 18:01:47 +01:00
parent 702b944698
commit b1cb9259da

View file

@ -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();