diff options
| author | Louise Crow <louise.crow@gmail.com> | 2015-02-05 11:06:25 +0000 | 
|---|---|---|
| committer | Louise Crow <louise.crow@gmail.com> | 2015-02-05 11:06:25 +0000 | 
| commit | 9e59c63c937a53526c0ae62644b0d300c039afa5 (patch) | |
| tree | e5a8afa1dfc2b9dae3e94cb8629b56dbc88048e3 | |
| parent | 865e1c044f0010284bb26fd59d7b55870b0a4155 (diff) | |
| parent | bac98e595afe6304bcd1f1f06e3472de33687182 (diff) | |
Merge branch 'hotfix/0.20.0.7' into rails-3-develop
Conflicts:
	config/initializers/alaveteli.rb
| -rw-r--r-- | app/controllers/general_controller.rb | 17 | ||||
| -rw-r--r-- | app/views/general/search.html.erb | 6 | ||||
| -rw-r--r-- | config/initializers/alaveteli.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/general_controller_spec.rb | 6 | 
4 files changed, 23 insertions, 8 deletions
| diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 2c8abbaf4..438bbfd3f 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -9,6 +9,8 @@ require 'open-uri'  class GeneralController < ApplicationController +    MAX_RESULTS = 500 +      # New, improved front page!      def frontpage          medium_cache @@ -124,38 +126,45 @@ class GeneralController < ApplicationController              end          end +        @page = get_search_page_from_params +          # Query each type separately for separate display (TODO: we are calling          # perform_search multiple times and it clobbers per_page for each one,          # so set as separate var)          requests_per_page = params[:requests_per_page] ? params[:requests_per_page].to_i : 25 -        @this_page_hits = @total_hits = @xapian_requests_hits = @xapian_bodies_hits = @xapian_users_hits = 0 +        # Later pages are very expensive to load +        if @page > MAX_RESULTS / requests_per_page +            raise ActiveRecord::RecordNotFound.new("Sorry. No pages after #{MAX_RESULTS / requests_per_page}.") +        end + +        @total_hits = @xapian_requests_hits = @xapian_bodies_hits = @xapian_users_hits = 0          if @requests              @xapian_requests = perform_search([InfoRequestEvent], @query, @sortby, 'request_collapse', requests_per_page)              @requests_per_page = @per_page -            @this_page_hits += @xapian_requests.results.size              @xapian_requests_hits = @xapian_requests.results.size              @xapian_requests_total_hits = @xapian_requests.matches_estimated              @total_hits += @xapian_requests.matches_estimated              @request_for_spelling = @xapian_requests +            @max_requests = (@xapian_requests.matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @xapian_requests.matches_estimated          end          if @bodies              @xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5)              @bodies_per_page = @per_page -            @this_page_hits += @xapian_bodies.results.size              @xapian_bodies_hits = @xapian_bodies.results.size              @xapian_bodies_total_hits = @xapian_bodies.matches_estimated              @total_hits += @xapian_bodies.matches_estimated              @request_for_spelling = @xapian_bodies +            @max_bodies = (@xapian_bodies.matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @xapian_bodies.matches_estimated          end          if @users              @xapian_users = perform_search([User], @query, @sortby, nil, 5)              @users_per_page = @per_page -            @this_page_hits += @xapian_users.results.size              @xapian_users_hits = @xapian_users.results.size              @xapian_users_total_hits = @xapian_users.matches_estimated              @total_hits += @xapian_users.matches_estimated              @request_for_spelling = @xapian_users +            @max_users = (@xapian_users.matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @xapian_users.matches_estimated          end          # Spelling and highight words are same for all three queries diff --git a/app/views/general/search.html.erb b/app/views/general/search.html.erb index 96c91b791..4f9ef5b68 100644 --- a/app/views/general/search.html.erb +++ b/app/views/general/search.html.erb @@ -161,7 +161,7 @@            <% end %>          </div> -        <%= will_paginate WillPaginate::Collection.new(@page, @bodies_per_page, @xapian_bodies.matches_estimated) %> +        <%= will_paginate WillPaginate::Collection.new(@page, @bodies_per_page, @max_bodies) %>        </div>         <% elsif @variety_postfix == 'bodies' %>            <p><%= raw(_('<a href="{{browse_url}}">Browse all</a> or <a href="{{add_url}}">ask us to add one</a>.', :browse_url => list_public_bodies_default_path.html_safe, :add_url => (help_requesting_path + '#missing_body').html_safe)) %></p> @@ -180,7 +180,7 @@              <%= render :partial => 'user/user_listing_single', :locals => { :display_user => result[:model] } %>            <% end %>          </div> -        <%= will_paginate WillPaginate::Collection.new(@page, @users_per_page, @xapian_users.matches_estimated) %> +        <%= will_paginate WillPaginate::Collection.new(@page, @users_per_page, @max_users) %>        </div>      <% end %> @@ -200,7 +200,7 @@            <% end %>          </div> -        <%= will_paginate WillPaginate::Collection.new(@page, @requests_per_page, @xapian_requests.matches_estimated) %> +        <%= will_paginate WillPaginate::Collection.new(@page, @requests_per_page, @max_requests) %>        </div>      <% end %>  <% end %> diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb index 4ae428405..48638f561 100644 --- a/config/initializers/alaveteli.rb +++ b/config/initializers/alaveteli.rb @@ -10,7 +10,7 @@ load "debug_helpers.rb"  load "util.rb"  # Application version -ALAVETELI_VERSION = '0.20.0.6' +ALAVETELI_VERSION = '0.20.0.7'  # Add new inflection rules using the following format  # (all these examples are active by default): diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 28dac7b96..128a42556 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -291,4 +291,10 @@ describe GeneralController, 'when using xapian search' do          response.body.should include('Track this search')      end +    it 'should not show high page offsets as these are extremely slow to generate' do +        lambda { +            get :search, :combined => 'bob/all', :page => 25 +        }.should raise_error(ActiveRecord::RecordNotFound) +    end +  end | 
