Sha256: 46bd7a2feaefd5213adff6d01f567b7a38fb68a001554f29f6901b58b10078a8

Contents?: true

Size: 776 Bytes

Versions: 18

Compression:

Stored size: 776 Bytes

Contents

module Workarea
  class BulkIndexAdmin
    include Sidekiq::Worker

    sidekiq_options lock: :until_executing

    class << self
      def perform(klass, ids)
        ids.each_slice(Workarea.config.bulk_index_batch_size) do |group|
          perform_by_models(klass.constantize.in(id: group).to_a)
        end
      end

      def perform_by_models(models)
        return if models.empty?
        Workarea::Search::Admin.bulk { documents_for(models) }
      end

      private

      def documents_for(models)
        models
          .map { |m| Workarea::Search::Admin.for(m) }
          .compact
          .select(&:should_be_indexed?)
          .map(&:as_bulk_document)
      end
    end

    def perform(klass, ids)
      self.class.perform(klass, ids)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.26 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.25 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.23 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.22 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.21 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.20 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.19 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.18 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.17 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.16 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.15 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.14 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.13 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.12 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.11 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.10 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.5.9 app/workers/workarea/bulk_index_admin.rb