activerecord_batch_update 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b05fc45c2f15bfd95ea4fd253abbadb17737572c10635d4c98955358e2706dee
4
- data.tar.gz: 6bde179e5c3385e1490bffacc4af6a7f855c915ccbcd864848a96c661bb137b9
3
+ metadata.gz: 2a66b5e19073d4edf987f73a8afa9152fc100360e7700aa8e2989f359612f3c7
4
+ data.tar.gz: bf8b7f7553e5a609656ef09e31a13b065d6266ebd88cfea9840ed955a8713aa8
5
5
  SHA512:
6
- metadata.gz: 789d85079a725aff4e9b1633450ce5b5526cc9af5cce9800a71c57358994b4dce27f838cf18023f522d47a65502ac6e331c88a211053636508c11740b9151b47
7
- data.tar.gz: cd88de04b2d63a0ca0da3cb9af797f7aa504fd45b17597d3941d9e0f21035495872d5fe024dd1c2f38f954708e13adc94be650c028af554d53e74d6d87c08061
6
+ metadata.gz: 6301c822318fa9170b01968d01a52362d7eee88f4e4a17c3733d1ad2ec6054caec8c59589e2ace60a37048bdc686ab9eb5ee3ac6784efc86baa7c435f193d5d5
7
+ data.tar.gz: 2a105e7a535bd4d81503a8873516ff9aad5f5a72c356d6d91b2bc1253fcf1025a5c80ea179cb46d1bf3e5bf0784f7035ce443521a17f4098d4e85ac474aa299a
@@ -14,7 +14,14 @@ module ActiveRecordBatchUpdate
14
14
  # which will re-insert the objects if they were deleted in another thread
15
15
 
16
16
  module ClassMethods
17
- def batch_update(entries, columns:, batch_size: 100, validate: true, clear_attribute_changes: true)
17
+ def batch_update(
18
+ entries,
19
+ columns:,
20
+ update_on: primary_key,
21
+ batch_size: 100,
22
+ validate: true,
23
+ clear_attribute_changes: true
24
+ )
18
25
  batch_update_ensure_entries_are_same_class!(entries)
19
26
 
20
27
  columns = column_names if columns == :all
@@ -24,13 +31,13 @@ module ActiveRecordBatchUpdate
24
31
  entries.each { _1.updated_at = Time.current } if has_attribute?('updated_at')
25
32
  entries.each(&:validate!) if validate
26
33
 
27
- primary_keys = Array.wrap(primary_key).map(&:to_s)
34
+ update_on = Array.wrap(update_on).map(&:to_s)
28
35
 
29
36
  updated_count = batch_update_statements(
30
37
  entries.map do |entry|
31
- (primary_keys + (entry.changed & columns)).to_h { [_1, entry.read_attribute(_1)] }
38
+ (update_on + (entry.changed & columns)).to_h { [_1, entry.read_attribute(_1)] }
32
39
  end,
33
- update_on: primary_keys,
40
+ update_on: update_on,
34
41
  batch_size: batch_size
35
42
  ).sum do |sql|
36
43
  connection.update(sql)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_batch_update
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quentin de Metz