active_touch 1.4.4 → 1.5.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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yzg5ZjE5MTA1NzBjNmM3OWEyNmM2ZTBkMTcxOTUxMzVjMmU4NWM2Mw==
4
+ Mjk4NzRlMTYzZDJlNDdjMmQwYzY3MmM3NWIyNzUwYjc1MDk0NjM4Zg==
5
5
  data.tar.gz: !binary |-
6
- NjBlODIxN2QwNDZhZGQyYjdiNGYwYzAzMThlYjdlMGM5NDU0MTA4Nw==
6
+ ODliZDdhNmJhYmZkMDMwMmU0YjJmYjk4YzU3M2JkYjMyMTllNGMwYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTkwNDkzODA3ZjNhNDMxNGNlMDg5ODY0ZTFlYWVmMDdmMjUzMWI1NmVjNTIz
10
- NThiYTA0OTQ0NGYxZjQ3YzVjNGI2NGQ4ZTZkYjRlNjhhYzFjMzJmNDNjNTA1
11
- OTk4YmMxNjg3Y2E2YWFjNGM2ZjhhYmZlZTMwZGQzOWVkODYzY2M=
9
+ MzcwOTk2ODhiOWI3ZWRiN2NkODNjYTI1ZGRmZTg4Njg3MDBmOTc3ZDM4MDky
10
+ YWZlZmIzODVkM2JiOTg0OTIxYTQyYTk1NjBiOTkwM2U2M2E5ODg0MDY5MWY5
11
+ ZGQxN2I1NzVkYWJhYTcwZjkzZDMxYjVlYTAwMmFlMDg1NGM4MjM=
12
12
  data.tar.gz: !binary |-
13
- NDYzNGM5NTNiOTMyYWJmNmU4MjUzMWE2NjE3ODY2ZmZmZjVmYzlmNzY4OGYw
14
- YmVmMjcxZWEzNmM4MTA3ZGQyN2FiMDlkZDBlYzcwZTA0ZTk5NGQ5M2Y1N2Jh
15
- ZWQ0ODllMmU0MDE0ODcwZGE0MDJlNDJmMDVmYjAwNmEzZGMyNDk=
13
+ NDgxMjNjYTYzMTJlZTgxNDY3M2EzNDhmMmVhYzIzOTAyMTgzZTRhZjAyMzY2
14
+ OTNiMGFlZDRmZjcyNzA2OWJmMjEyZDg5ZjQ2MjJlN2MwOTA5MmRhYmIwMmI2
15
+ ZDRmZDQzZTIyNGM1ZGMxNDk2OTUwZjIwMzUyODRhNzAzZjVjNTU=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_touch (1.4.3)
4
+ active_touch (1.4.4)
5
5
  rails (~> 4.2)
6
6
 
7
7
  GEM
@@ -13,10 +13,11 @@ module ActiveTouch
13
13
  end
14
14
 
15
15
  class Configuration
16
- attr_accessor :async, :ignored_attributes, :queue
16
+ attr_accessor :async, :batch_size, :ignored_attributes, :queue
17
17
 
18
18
  def initialize
19
19
  @async = false
20
+ @batch_size = 100
20
21
  @ignored_attributes = [:updated_at]
21
22
  @queue = 'default'
22
23
  end
@@ -1,27 +1,19 @@
1
1
  module ActiveTouch
2
2
  class TouchJob < ActiveJob::Base
3
3
 
4
- def perform(record, association, after_touch, is_async)
5
- if association == 'self'
6
- associated = record
7
- else
8
- associated = record.send(association)
9
- end
4
+ def perform(record, association, after_touch, is_async = false)
5
+ associated = association == 'self' ? record : record.send(association)
10
6
 
11
7
  if associated.is_a? ActiveRecord::Base
12
8
  associated.update_columns(updated_at: record.updated_at)
13
9
  associated.send(after_touch) unless after_touch.blank?
14
10
 
15
11
  elsif !associated.nil?
16
- associated.each do |associate|
17
12
 
18
- if is_async
19
- TouchJob
20
- .set(queue: ActiveTouch.configuration.queue)
21
- .perform_later(associate, 'self', after_touch, is_async)
22
- else
23
- TouchJob.perform_later(associate, 'self', after_touch, is_async)
24
- end
13
+ 0.step(associated.count, ActiveTouch.configuration.batch_size).each do |offset|
14
+ batch = associated.offset(offset).limit(ActiveTouch.configuration.batch_size)
15
+ batch.update_all(updated_at: record.updated_at)
16
+ batch.each { |associate| associate.send(after_touch) } unless after_touch.blank?
25
17
  end
26
18
  end
27
19
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveTouch
2
- VERSION = '1.4.4'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -3,6 +3,10 @@ ActiveTouch.configure do |config|
3
3
  # Default is false
4
4
  # config.async = false
5
5
 
6
+ # Batch size of records to touch at a time
7
+ # Default is 100
8
+ # config.batch_size = 100
9
+
6
10
  # When :watch is not specified, ignore the following attributes.
7
11
  # Default is [:updated_at]
8
12
  # config.ignored_attributes = [:updated_at]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_touch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Pheasey