From: Tom Hughes Date: Fri, 21 May 2010 19:21:41 +0000 (+0100) Subject: Add a timeout to the change list pages X-Git-Tag: live~6320^2~7 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/cf682f49b37a533e7e7aa5f8ea879ba970e88490 Add a timeout to the change list pages --- diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a53fb5374..c7c6c4add 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -216,6 +216,8 @@ class ApplicationController < ActionController::Base raise OSM::APIBadMethodError.new(method) unless ok end + ## + # wrap an api call in a timeout def api_call_timeout SystemTimer.timeout_after(APP_CONFIG['api_timeout']) do yield @@ -224,6 +226,22 @@ class ApplicationController < ActionController::Base raise OSM::APITimeoutError end + ## + # wrap a web page in a timeout + def web_timeout + SystemTimer.timeout_after(APP_CONFIG['web_timeout']) do + yield + end + rescue ActionView::TemplateError => ex + if ex.original_exception.is_a?(Timeout::Error) + render :action => "timeout" + else + raise + end + rescue Timeout::Error + render :action => "timeout" + end + ## # extend caches_action to include the parameters, locale and logged in # status in all cache keys diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index a511d67d3..9aec1060a 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -4,7 +4,7 @@ class BrowseController < ApplicationController before_filter :authorize_web before_filter :set_locale before_filter { |c| c.check_database_readable(true) } - around_filter :timeout, :except => [:start] + around_filter :web_timeout, :except => [:start] def start end @@ -77,20 +77,4 @@ class BrowseController < ApplicationController rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end - -private - - def timeout - SystemTimer.timeout_after(30) do - yield - end - rescue ActionView::TemplateError => ex - if ex.original_exception.is_a?(Timeout::Error) - render :action => "timeout" - else - raise - end - rescue Timeout::Error - render :action => "timeout" - end end diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index e17d652ad..1b77d48ee 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -12,7 +12,8 @@ class ChangesetController < ApplicationController before_filter :check_api_writable, :only => [:create, :update, :delete, :upload, :include] before_filter :check_api_readable, :except => [:create, :update, :delete, :upload, :download, :query] after_filter :compress_output - around_filter :api_call_handle_error + around_filter :api_call_handle_error, :except => [:list, :list_user, :list_bbox] + around_filter :web_timeout, :only => [:list, :list_user, :list_bbox] filter_parameter_logging " I18n.locale, :schema_date => 2009, + :id => url_for(params.merge({ :only_path => false })), + :root_url => url_for(params.merge({ :only_path => false, :format => nil })), + "xmlns:georss" => "http://www.georss.org/georss") do |feed| + feed.title @title + + feed.subtitle :type => 'xhtml' do |xhtml| + xhtml.p do |p| + p << t('changeset.timeout.sorry') + end + end +end diff --git a/app/views/changeset/timeout.html.erb b/app/views/changeset/timeout.html.erb new file mode 100644 index 000000000..a52255722 --- /dev/null +++ b/app/views/changeset/timeout.html.erb @@ -0,0 +1 @@ +

<%= t'changeset.timeout.sorry' %>

diff --git a/config/application.yml b/config/application.yml index d40570965..1b38f8f74 100644 --- a/config/application.yml +++ b/config/application.yml @@ -13,6 +13,8 @@ standard_settings: &standard_settings geonames_zoom: 12 # Timeout for API calls in seconds api_timeout: 300 + # Timeout for web pages in seconds + web_timeout: 30 # Periods (in hours) which are allowed for user blocks user_block_periods: [0, 1, 3, 6, 12, 24, 48, 96] # Rate limit for message sending diff --git a/config/locales/en.yml b/config/locales/en.yml index a92a7fe19..e4b0ee214 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -297,6 +297,8 @@ en: description_user: "Changesets by {{user}}" description_bbox: "Changesets within {{bbox}}" description_user_bbox: "Changesets by {{user}} within {{bbox}}" + timeout: + sorry: "Sorry, the list of changesets you requested took too long to retrieve." diary_entry: new: title: New Diary Entry