Skip to content

Commit

Permalink
Fixing rails 3.0.x compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
njakobsen committed Oct 24, 2012
1 parent 849d879 commit 695297d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sunspot_rails/lib/sunspot/rails/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,17 @@ def solr_index(opts={})
#
# Array:: Collection of IDs that exist in Solr but not in the database
def solr_index_orphans(opts={})
batch_size = opts[:batch_size] || Sunspot.config.indexing.default_batch_size
count = self.count
indexed_ids = solr_search_ids { paginate(:page => 1, :per_page => count) }.to_set
find_each(:select => 'id', :batch_size => batch_size) do |object|
indexed_ids.delete(object.id)
batch_size = opts[:batch_size] || Sunspot.config.indexing.default_batch_size

solr_page = 0
solr_ids = []
while (solr_page = solr_page.next)
ids = solr_search_ids { paginate(:page => solr_page, :per_page => 1000) }.to_a
break if ids.empty?
solr_ids.concat ids
end
indexed_ids.to_a

return solr_ids - self.connection.select_values("SELECT id FROM #{quoted_table_name}").collect(&:to_i)
end

#
Expand Down

0 comments on commit 695297d

Please sign in to comment.