diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-05-18 23:29:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-18 23:29:14 +0200 |
commit | 679b7158e3cd3881e8cbaf2d2c0c97725b3b5fd9 (patch) | |
tree | 9cc1dd73c3cd894207bf3c806234c8c919459985 /app/workers | |
parent | ded5a0254a4d29a7384ef766a1e92467fe4ebd2b (diff) |
Change search indexing to use batches to minimize resource usage (#18451)
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/scheduler/indexing_scheduler.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/workers/scheduler/indexing_scheduler.rb b/app/workers/scheduler/indexing_scheduler.rb new file mode 100644 index 000000000..3a6f47a29 --- /dev/null +++ b/app/workers/scheduler/indexing_scheduler.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class Scheduler::IndexingScheduler + include Sidekiq::Worker + include Redisable + + sidekiq_options retry: 0 + + def perform + 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) } + end + end + end + end + + def indexes + [AccountsIndex, TagsIndex, StatusesIndex] + end +end |