Skip to content

Commit

Permalink
Don't run full guide reindex on garden save.
Browse files Browse the repository at this point in the history
Reindex each guide individually in order of popularity.
  • Loading branch information
guitsaru committed Mar 3, 2015
1 parent 8376bb5 commit 87dda23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/jobs/reindex_guides_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class ReindexGuidesJob < ActiveJob::Base
queue_as :default

def perform
Guide.reindex
Guide.desc(:popularity_score).each do |guide|
guide.reindex_async
end
end
end
4 changes: 3 additions & 1 deletion spec/jobs/reindex_guides_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

describe ReindexGuidesJob do
it 'reindexes guides' do
expect(Guide).to receive(:reindex)
FactoryGirl.create(:guide)

expect_any_instance_of(Guide).to receive(:reindex_async)

ReindexGuidesJob.new.perform
end
Expand Down
4 changes: 3 additions & 1 deletion spec/models/garden_crop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
end

it 'reindexes guides' do
expect(Guide).to receive(:reindex)
FactoryGirl.create(:guide)

expect_any_instance_of(Guide).to receive(:reindex_async)

FactoryGirl.create(:garden, user: FactoryGirl.create(:user))
end
Expand Down

0 comments on commit 87dda23

Please sign in to comment.