IndexingScheduler: fetch and import in batches (#24285)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Vyr CossontandClaire authored and Tarrien committed 2023-12-14 14:10:06 -05:00
1 parent 7d6a3b5527
commit 3ad7411029
1 file changed
+7 -9
+7 -9
View File
@@ -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