active_touch 1.4.4 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Mjk4NzRlMTYzZDJlNDdjMmQwYzY3MmM3NWIyNzUwYjc1MDk0NjM4Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODliZDdhNmJhYmZkMDMwMmU0YjJmYjk4YzU3M2JkYjMyMTllNGMwYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzcwOTk2ODhiOWI3ZWRiN2NkODNjYTI1ZGRmZTg4Njg3MDBmOTc3ZDM4MDky
|
10
|
+
YWZlZmIzODVkM2JiOTg0OTIxYTQyYTk1NjBiOTkwM2U2M2E5ODg0MDY5MWY5
|
11
|
+
ZGQxN2I1NzVkYWJhYTcwZjkzZDMxYjVlYTAwMmFlMDg1NGM4MjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDgxMjNjYTYzMTJlZTgxNDY3M2EzNDhmMmVhYzIzOTAyMTgzZTRhZjAyMzY2
|
14
|
+
OTNiMGFlZDRmZjcyNzA2OWJmMjEyZDg5ZjQ2MjJlN2MwOTA5MmRhYmIwMmI2
|
15
|
+
ZDRmZDQzZTIyNGM1ZGMxNDk2OTUwZjIwMzUyODRhNzAzZjVjNTU=
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
data/lib/active_touch/version.rb
CHANGED
@@ -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]
|