lib/blind_index/backfill.rb in blind_index-2.0.1 vs lib/blind_index/backfill.rb in blind_index-2.0.2

- old
+ new

@@ -52,11 +52,11 @@ end end relation.merge(or_relation) else - relation.or(attributes.map { |a| {a => nil} }) + relation.merge(relation.unscoped.or(attributes.map { |a| {a => nil} })) end end def each_batch relation = build_relation @@ -86,14 +86,17 @@ blind_indexes.each do |k, v| record.send("compute_#{k}_bidx") if !record.send(v[:bidx_attribute]) end end + # don't need to save records that went from nil => nil records.select! { |r| r.changed? } - with_transaction do - records.each do |record| - record.save!(validate: false) + if records.any? + with_transaction do + records.each do |record| + record.save!(validate: false) + end end end end def with_transaction