Skip to content

Commit

Permalink
Merge branch 'hotfix/1.9.3' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Glen committed Jan 3, 2013
2 parents 3eec8e2 + 73d056a commit 01c3a67
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
15 changes: 9 additions & 6 deletions app/controllers/dt/projects_controller.rb
Expand Up @@ -22,12 +22,15 @@ def index
@search_text = ""
else
@search_text = params[:search][:search_text].present? ? params[:search][:search_text] : ""
@projects = Project.search @search_text,
:with => search_query_prepared,
:page => params[:page],
:per_page => (params[:per_page].blank? ? 18 : params[:per_page].to_i),
:order => (params[:order].blank? ? :project_status_id : params[:order].to_sym),
:populate => true
Search.with_retries do # this should help with the "index not preread" errors
@projects = Project.search(@search_text, {
:with => search_query_prepared,
:page => params[:page],
:per_page => (params[:per_page].blank? ? 18 : params[:per_page].to_i),
:order => (params[:order].blank? ? :project_status_id : params[:order].to_sym),
:populate => true
})
end
end
# NOTE: we're assuming the project_status_id for 'active' is lower than 'completed' for each order above
respond_to do |format|
Expand Down
19 changes: 11 additions & 8 deletions app/controllers/iend/users_controller.rb
Expand Up @@ -10,12 +10,15 @@ def index
if params[:name].blank? && params[:sectors].blank? && params[:project].blank? && params[:country].blank?
@profiles = IendProfile.paginate(:page => params[:page], :per_page => 18)
else
@profiles = IendProfile.search params[:name],
:with_all => search_prepare_with_all,
:without => search_prepare_without,
:page => params[:page],
:per_page => (params[:per_page].blank? ? 18 : params[:per_page].to_i),
:order => (params[:order].blank? ? :created_at : params[:order].to_sym)
Search.with_retries do # this should help with the "index not preread" errors
@profiles = IendProfile.search(params[:name], {
:with_all => search_prepare_with_all,
:without => search_prepare_without,
:page => params[:page],
:per_page => (params[:per_page].blank? ? 18 : params[:per_page].to_i),
:order => (params[:order].blank? ? :created_at : params[:order].to_sym)
})
end
end
respond_to do |format|
format.html { render :action => "index", :layout => "iend_users_search"}
Expand All @@ -27,7 +30,7 @@ def show
@user ||= User.find(params[:id])
@iend_profile = @user.iend_profile

@gifts_given_count = @user.gifts.count
@gifts_given_count = @user.gifts.count
@given_amount = @user.orders.sum(:total)
@people_affected = @user.profile.people_impacted.first

Expand Down Expand Up @@ -128,7 +131,7 @@ def search_prepare_with_all
end

def sector_params_array
params[:sectors].try(:split, /\s|\+|,/).to_a
params[:sectors].try(:split, /\s|\+|,/).to_a.select{|v| v == v.to_i.to_s }.map(&:to_i)
end

def sector_add(sector_id)
Expand Down
23 changes: 23 additions & 0 deletions app/models/search.rb
@@ -0,0 +1,23 @@
class Search
MAX_ATTEMPTS = 5

# this should help with the "index not prerea"d errors
# the error happens when somebody searches the moment that sphinx is rotating
# the indexes, which happens very quickly. This gives it a chance to finish
# and still return results instead of a 500 error - see https://gist.github.com/1818244
def self.with_retries
attempt = 0
begin
yield
rescue ThinkingSphinx::SphinxError
# We over-eagerly rescue all Sphinx errors. But since we re-raise them
# if they still fail after a few attempts, we don't hide anything.
attempt += 1
if attempt > MAX_ATTEMPTS
raise
else
retry
end
end
end
end
2 changes: 1 addition & 1 deletion config/initializers/version.rb
@@ -1,5 +1,5 @@
module Donortrust
unless defined?(Donortrust::VERSION)
VERSION = '1.9.2'
VERSION = '1.9.3'
end
end

0 comments on commit 01c3a67

Please sign in to comment.