Project

General

Profile

Patch #16069

Updated by Toshi MARUYAMA over 6 years ago

The below tested patch makes the previously harcoded limit of 100 items in a RESTful API response configurable in the Administration GUI. The default value is still 100. This is based on 2.4.1.stable. 

 This is quite useful since it is nice and simple to just get the full response in a single page rather than having to traverse pagination, and a limit of a bit more than 100 is still very performant for many sites -- the limit beyond which performance starts to degrade really depends on the particular site's usage, so should be controllable by the local administrator. 

 <pre><code class="diff"> <pre> 
 Index: app/controllers/application_controller.rb 
 =================================================================== 
 --- app/controllers/application_controller.rb         (.../trunk/app) (revision 13385) 
 +++ app/controllers/application_controller.rb         (.../branches/code-8112/app)      (revision 13389) 
 @@ -519,8 +519,8 @@ 
      limit = options[:limit].to_i 
      if limit < 1 
        limit = 25 
 -      elsif limit > 100 
 -        limit = 100 
 +      elsif limit > Setting.api_limit.to_i 
 +        limit = Setting.api_limit.to_i 
      end 
      if offset.nil? && options[:page].present? 
        offset = (options[:page].to_i - 1) * limit 
 Index: app/views/settings/_general.html.erb 
 =================================================================== 
 --- app/views/settings/_general.html.erb      (.../trunk/app) (revision 13385) 
 +++ app/views/settings/_general.html.erb      (.../branches/code-8112/app)      (revision 13389) 
 @@ -24,6 +24,8 @@ 
 
  <p><%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %></p> 
 
 +<p><%= setting_text_field :api_limit, :size => 6 %></p> 
 + 
  <p><%= setting_text_field :feeds_limit, :size => 6 %></p> 
 
  <p><%= setting_text_field :file_max_size_displayed, :size => 6 %> <%= l(:"number.human.storage_units.units.kb") %></p> 
 Index: config/settings.yml 
 =================================================================== 
 --- config/settings.yml          (revision 13387) 
 +++ config/settings.yml          (revision 13389) 
 @@ -73,6 +73,9 @@ 
    default: localhost:3000 
  protocol: 
    default: http 
 +api_limit: 
 +    format: int 
 +    default: 100 
  feeds_limit: 
    format: int 
    default: 15 
 Index: config/locales/en.yml 
 =================================================================== 
 --- config/locales/en.yml        (revision 13387) 
 +++ config/locales/en.yml        (revision 13389) 
 @@ -352,6 +352,7 @@ 
    setting_host_name: Host name and path 
    setting_text_formatting: Text formatting 
    setting_wiki_compression: Wiki history compression 
 +    setting_api_limit: Maximum number of items returned in a JSON/XML API response 
    setting_feeds_limit: Maximum number of items in Atom feeds 
    setting_default_projects_public: New projects are public by default 
    setting_autofetch_changesets: Fetch commits automatically 

 </code></pre> </pre>

Back