Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/models/search/indexer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Indexer
BATCH_SIZE = 1000
INDEXERS_FOR_CLASS = {
Work: %w[WorkIndexer WorkCreatorIndexer BookmarkedWorkIndexer],
Bookmark: %w[BookmarkIndexer],
Expand Down Expand Up @@ -124,15 +123,19 @@ def self.index_all(options = {})
end

def self.index_from_db
total = (indexables.count / BATCH_SIZE) + 1
total = (indexables.count / batch_size) + 1
i = 1
indexables.find_in_batches(batch_size: BATCH_SIZE) do |group|
indexables.find_in_batches(batch_size: batch_size) do |group|
puts "Queueing #{klass} batch #{i} of #{total}" unless Rails.env.test?
AsyncIndexer.new(self, :world).enqueue_ids(group.map(&:id))
i += 1
end
end

def self.batch_size
ArchiveConfig.SEARCH_INDEXER_BATCH_SIZE
end

# Add conditions here
def self.indexables
klass.constantize
Expand Down
3 changes: 3 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ MINUTES_UNTIL_COLLECTION_BLURBS_EXPIRE: 120
# Job size used for the HitCountUpdateJob class:
HIT_COUNT_JOB_SIZE: 1000

# Batch size used by Indexer when reading records from the database:
SEARCH_INDEXER_BATCH_SIZE: 1000

# Batch size used for the HitCountUpdateJob class:
HIT_COUNT_BATCH_SIZE: 100

Expand Down
20 changes: 20 additions & 0 deletions spec/models/search/indexer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "spec_helper"

describe Indexer do
describe ".index_from_db" do
let!(:work1) { create(:work) }
let!(:work2) { create(:work) }
let(:async_indexer) { instance_double(AsyncIndexer, enqueue_ids: true) }

before do
allow(ArchiveConfig).to receive(:SEARCH_INDEXER_BATCH_SIZE).and_return(1)
allow(AsyncIndexer).to receive(:new).and_return(async_indexer)
end

it "uses the configured batch size when indexing" do
WorkIndexer.index_from_db

expect(async_indexer).to have_received(:enqueue_ids).twice
end
end
end
Loading