Skip to content

Commit

Permalink
a little bit of work to make this to work well on lastest Rails versi…
Browse files Browse the repository at this point in the history
…on (3)
  • Loading branch information
thiagomoretto committed Mar 18, 2011
1 parent 216d745 commit fafafac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions lib/acts_as_ferret.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ def self.retrieve_records(id_arrays, find_options = {})
end

# fetch
tmp_result = model_class.find(:all, find_options.merge(:conditions => conditions,
:include => filtered_include_options))
tmp_result = model_class.where(find_options.merge(:conditions => conditions)[:conditions]).includes(filtered_include_options).all

# set scores and rank
tmp_result.each do |record|
Expand Down
10 changes: 5 additions & 5 deletions lib/acts_as_ferret/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def records_modified_since(time)
logger.warn "#{self.name}: Override records_modified_since(time) to keep the index up to date with records changed during rebuild."
[]
else
find :all, :conditions => [ condition.join(' AND '), *([time]*condition.size) ]
where([ condition.join(' AND '), *([time]*condition.size) ]).all
end
end

Expand All @@ -74,14 +74,14 @@ def records_for_rebuild(batch_size = 1000)
transaction do
if use_fast_batches?
offset = 0
while (rows = find :all, :conditions => [ "#{table_name}.id > ?", offset ], :limit => batch_size).any?
while (rows = where([ "#{table_name}.id > ?", offset ]).limit(batch_size).all).any?
offset = rows.last.id
yield rows, offset
end
else
order = "#{primary_key} ASC" # fixes #212
0.step(self.count, batch_size) do |offset|
yield find( :all, :limit => batch_size, :offset => offset, :order => order ), offset
yield scoped.limit(batch_size).offset(offset).order(order).all, offset
end
end
end
Expand All @@ -92,9 +92,9 @@ def records_for_bulk_index(ids, batch_size = 1000)
transaction do
offset = 0
ids.each_slice(batch_size) do |id_slice|
records = find( :all, :conditions => ["id in (?)", id_slice] )
records = where(:id => id_slice).all
#yield records, offset
yield find( :all, :conditions => ["id in (?)", id_slice] ), offset
yield where(:id => id_slice).all, offset
offset += batch_size
end
end
Expand Down

0 comments on commit fafafac

Please sign in to comment.