Module: Elasticsearch::Model::Extensions::BatchUpdating::Association::Extension
- Defined in:
- lib/elasticsearch/model/extensions/batch_updating.rb
Instance Method Summary collapse
- #update_index_for_ids_from(from, to:, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) ⇒ Object
- #update_index_for_ids_in_range(range, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) ⇒ Object
- #update_index_in_batches(batch_size: DEFAULT_BATCH_SIZE, index: nil, type: nil) ⇒ Object
- #update_index_in_chunks(num, index: index) ⇒ Object
Instance Method Details
#update_index_for_ids_from(from, to:, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 78 def update_index_for_ids_from(from, to:, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) record_id = arel_table[:id] conditions = record_id.gteq(from).and(record_id.lteq(to)) where(conditions).update_index_in_batches(batch_size: batch_size, index: index, type: type) end |
#update_index_for_ids_in_range(range, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) ⇒ Object
86 87 88 |
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 86 def update_index_for_ids_in_range(range, index: nil, type: nil, batch_size: DEFAULT_BATCH_SIZE) update_index_for_ids_from(range.first, to: range.last, type: type, index: index, batch_size: batch_size) end |
#update_index_in_batches(batch_size: DEFAULT_BATCH_SIZE, index: nil, type: nil) ⇒ Object
90 91 92 93 94 |
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 90 def update_index_in_batches(batch_size: DEFAULT_BATCH_SIZE, index: nil, type: nil) find_in_batches(batch_size: batch_size) do |records| __batch_updater__.update_index_in_batch(records, index: index, type: type) end end |
#update_index_in_chunks(num, index: index) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/elasticsearch/model/extensions/batch_updating.rb', line 68 def update_index_in_chunks(num, index: index) klass.split_ids_into(num).map do |r| if block_given? yield -> { update_index_for_ids_in_range(r, index: index) } else update_index_for_ids_in_range(r, index: index) end end end |