Skip to content

Commit

Permalink
IndexingScheduler: fetch and import in batches (mastodon#24285)
Browse files Browse the repository at this point in the history
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
  • Loading branch information
VyrCossont and ClearlyClaire committed Jul 4, 2023
1 parent 926114d commit 4ebe599
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/workers/scheduler/indexing_scheduler.rb
Expand Up @@ -6,17 +6,21 @@ class Scheduler::IndexingScheduler

sidekiq_options retry: 0

IMPORT_BATCH_SIZE = 1000
SCAN_BATCH_SIZE = 10 * IMPORT_BATCH_SIZE

def perform
return unless Chewy.enabled?

indexes.each do |type|
with_redis do |redis|
ids = redis.smembers("chewy:queue:#{type.name}")

type.import!(ids)

redis.pipelined do |pipeline|
ids.each { |id| pipeline.srem("chewy:queue:#{type.name}", id) }
redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE) do |ids|
redis.pipelined do
ids.each_slice(IMPORT_BATCH_SIZE) do |slice_ids|
type.import!(slice_ids)
redis.srem("chewy:queue:#{type.name}", slice_ids)
end
end
end
end
end
Expand Down

0 comments on commit 4ebe599

Please sign in to comment.