X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e34d6859d936f0b82f981d44be415a46b1aa61e1..c550609485691d8107ae364bfc982569f81f1725:/services/api/lib/load_param.rb diff --git a/services/api/lib/load_param.rb b/services/api/lib/load_param.rb index 8d5a9d21ee..35f1d0b640 100644 --- a/services/api/lib/load_param.rb +++ b/services/api/lib/load_param.rb @@ -6,9 +6,12 @@ # @where, @filters, @limit, @offset, @orders module LoadParam - # Default limit on number of rows to return in a single query. + # Default number of rows to return in a single query. DEFAULT_LIMIT = 100 + # Maximum number of rows to return in a single query, even if the client asks for more. + MAX_LIMIT = 1000 + # Load params[:where] into @where def load_where_param if params[:where].nil? or params[:where] == "" @@ -44,10 +47,6 @@ module LoadParam end end - def default_orders - ["#{table_name}.modified_at desc"] - end - # Load params[:limit], params[:offset] and params[:order] # into @limit, @offset, @orders def load_limit_offset_order_params @@ -55,7 +54,7 @@ module LoadParam unless params[:limit].to_s.match(/^\d+$/) raise ArgumentError.new("Invalid value for limit parameter") end - @limit = params[:limit].to_i + @limit = [params[:limit].to_i, MAX_LIMIT].min else @limit = DEFAULT_LIMIT end @@ -110,9 +109,11 @@ module LoadParam end end - if @orders.empty? - @orders = default_orders - end + # If the client-specified orders don't amount to a full ordering + # (e.g., [] or ['owner_uuid desc']), fall back on the default + # orders to ensure repeating the same request (possibly with + # different limit/offset) will return records in the same order. + @orders += model_class.default_orders case params[:select] when Array