From 3ad7411029ff89268eb94b5f97a480107e034ace Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Fri, 31 Mar 2023 05:38:47 -0700 Subject: [PATCH] IndexingScheduler: fetch and import in batches (#24285) Co-authored-by: Claire --- app/workers/scheduler/indexing_scheduler.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/workers/scheduler/indexing_scheduler.rb b/app/workers/scheduler/indexing_scheduler.rb index 5c985e25a0..c423966297 100644 --- a/app/workers/scheduler/indexing_scheduler.rb +++ b/app/workers/scheduler/indexing_scheduler.rb @@ -3,28 +3,26 @@ class Scheduler::IndexingScheduler include Sidekiq::Worker include Redisable - include DatabaseHelper - sidekiq_options retry: 0, lock: :until_executed, lock_ttl: 30.minutes.to_i - - IMPORT_BATCH_SIZE = 1000 - SCAN_BATCH_SIZE = 10 * IMPORT_BATCH_SIZE + sidekiq_options retry: 0 def perform return unless Chewy.enabled? indexes.each do |type| with_redis do |redis| - redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE).each_slice(IMPORT_BATCH_SIZE) do |ids| - type.import!(ids) + ids = redis.smembers("chewy:queue:#{type.name}") - redis.srem("chewy:queue:#{type.name}", ids) + type.import!(ids) + + redis.pipelined do |pipeline| + ids.each { |id| pipeline.srem("chewy:queue:#{type.name}", id) } end end end end def indexes - [AccountsIndex, TagsIndex, PublicStatusesIndex, StatusesIndex] + [AccountsIndex, TagsIndex, StatusesIndex] end end