Skip to content

Commit

Permalink
+ evaluate source block once for each indexing stage
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Dec 13, 2011
1 parent 1753ee3 commit ec4cd08
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions server/lib/picky/indexers/base.rb
Expand Up @@ -20,21 +20,22 @@ def initialize index_or_category
# Starts the indexing process.
#
def prepare categories, scheduler = Scheduler.new
check_source
source_for_prepare = source
check source_for_prepare
categories.empty
process categories, scheduler do |prepared_file|
process source_for_prepare, categories, scheduler do |prepared_file|
notify_finished prepared_file
end
end

# Explicitly reset the source to avoid caching trouble.
#
def reset_source
def reset source
source.reset if source.respond_to?(:reset)
source.reconnect! if source.respond_to?(:reconnect!)
end

def check_source # :nodoc:
def check source # :nodoc:
raise "Trying to index without a source for #{@index_or_category.name}." unless source
end

Expand Down
6 changes: 3 additions & 3 deletions server/lib/picky/indexers/parallel.rb
Expand Up @@ -15,7 +15,7 @@ class Parallel < Base
# Parameters:
# * categories: An Enumerable of Category-s.
#
def process categories, scheduler = Scheduler.new
def process source_for_prepare, categories, scheduler = Scheduler.new
# Prepare a combined object - array.
#
combined = categories.map do |category|
Expand All @@ -26,9 +26,9 @@ def process categories, scheduler = Scheduler.new
#
objects = []

reset_source
reset source_for_prepare

source.each do |object|
source_for_prepare.each do |object|

# Accumulate objects.
#
Expand Down
4 changes: 2 additions & 2 deletions server/lib/picky/indexers/serial.rb
Expand Up @@ -16,7 +16,7 @@ class Serial < Base
# Parameters:
# * categories: An enumerable of Category-s.
#
def process categories, scheduler = Scheduler.new
def process source_for_prepare, categories, scheduler = Scheduler.new
categories.each do |category|

category.prepared_index_file do |file|
Expand All @@ -25,7 +25,7 @@ def process categories, scheduler = Scheduler.new
result = []
tokenizer = category.tokenizer

reset_source
reset source_for_prepare

source.harvest(category) do |*data|

Expand Down
2 changes: 1 addition & 1 deletion server/spec/lib/indexers/base_spec.rb
Expand Up @@ -35,7 +35,7 @@
it 'processes' do
categories = stub :categories, :empty => nil, :cache => nil

indexer.should_receive(:process).once.with categories, anything
indexer.should_receive(:process).once.with :some_source, categories, anything

indexer.prepare categories
end
Expand Down

0 comments on commit ec4cd08

Please sign in to comment.