Skip to content

A free open source IT asset/license management system

Merge branch 'develop' into up/stable-uploaded-files-sort

snipe713a719aeb91
diff --cc app/Http/Controllers/Api/UploadedFilesController.php
index a1220be9f5,60b892a8f8..3fdf70c4cd
--- a/app/Http/Controllers/Api/UploadedFilesController.php
+++ b/app/Http/Controllers/Api/UploadedFilesController.php
@@@ -70,11 -69,13 +69,16 @@@ class UploadedFilesController extends C
);
}
+ // $total must be computed after the search where() block so both
+ // the offset clamp and the response total reflect the filtered
+ // set. Previously the offset ran on the unfiltered count, which
+ // could over-clamp when a search narrowed results.
$total = $uploads->count();
+ // Secondary sort by id so files uploaded within the same second (a
+ // common case in tests and bulk uploads) return in a stable order
+ // rather than whatever the engine happens to pick.
+ $offset = ($request->input('offset') > $total) ? $total : app('api_offset_value');
- $uploads = $uploads->skip($offset)->take($limit)->orderBy($sort, $order)->get();
+ $uploads = $uploads->skip($offset)->take($limit)->orderBy($sort, $order)->orderBy('id', $order)->get();
return (new UploadedFilesTransformer)->transformFiles($uploads, $total);
}