Sha256: 611968fc3777156034842d2d84b532c3cdccd01ddf31e32a3da0a071bd16aaf3

Contents?: true

Size: 739 Bytes

Versions: 19

Compression:

Stored size: 739 Bytes

Contents

module Workarea
  class BulkIndexAdmin
    include Sidekiq::Worker

    sidekiq_options lock: :until_executing

    class << self
      def perform(klass, ids)
        ids.each_slice(100) 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

19 entries across 19 versions & 1 rubygems

Version Path
workarea-core-3.4.30 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.29 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.28 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.27 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.26 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.25 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.24 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.23 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.22 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.21 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.20 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.19 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.18 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.17 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.16 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.15 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.14 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.13 app/workers/workarea/bulk_index_admin.rb
workarea-core-3.4.12 app/workers/workarea/bulk_index_admin.rb