activerecord-delay_touching 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6f6e8902b0825be4680b4fe982948f644dd585fbe075fdfa64e7452afc18274d
|
4
|
+
data.tar.gz: b38c413cd1159118323390208b8ff53a98c01f94c0493b43641b275bc4810fb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c07d67c08967b9ff4738d8d351e91702c12f9c0af79bbe90802abad098efe38c1d58c5d558ecc097ed5aa645f0b000f07ea2aec86360c0ca6bcd6ab65b73e7cd
|
7
|
+
data.tar.gz: 216fd4bb29889f49cb0b964e514751dad55f7d9af0fde877ac46ccebd0f77f6ad7b9aa3336e5830578d7cb0a82be9d655175f4db7588376e2f5ca327c309ec9e
|
@@ -6,8 +6,8 @@ require 'activerecord/delay_touching/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "activerecord-delay_touching"
|
8
8
|
spec.version = Activerecord::DelayTouching::VERSION
|
9
|
-
spec.authors = ["Brian Morearty"]
|
10
|
-
spec.email = ["brian@morearty.org"]
|
9
|
+
spec.authors = ["GoDaddy P&C Commerce", "Brian Morearty"]
|
10
|
+
spec.email = ["nemo-engg@godaddy.com", "brian@morearty.org"]
|
11
11
|
spec.summary = %q{Batch up your ActiveRecord "touch" operations for better performance.}
|
12
12
|
spec.description = %q{Batch up your ActiveRecord "touch" operations for better performance. ActiveRecord::Base.delay_touching do ... end. When "end" is reached, all accumulated "touch" calls will be consolidated into as few database round trips as possible.}
|
13
13
|
spec.homepage = ""
|
@@ -18,13 +18,13 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "activerecord", "
|
21
|
+
spec.add_dependency "activerecord", "~> 4.2"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "sqlite3"
|
26
26
|
spec.add_development_dependency "timecop"
|
27
|
-
spec.add_development_dependency "rspec-rails", "~>
|
27
|
+
spec.add_development_dependency "rspec-rails", "~> 3.0"
|
28
28
|
spec.add_development_dependency "simplecov"
|
29
29
|
spec.add_development_dependency "simplecov-rcov"
|
30
30
|
spec.add_development_dependency "yarjuf"
|
@@ -86,7 +86,8 @@ module ActiveRecord
|
|
86
86
|
column = column.to_s
|
87
87
|
changes[column] = current_time
|
88
88
|
records.each do |record|
|
89
|
-
|
89
|
+
# Don't bother if destroyed or not-saved
|
90
|
+
next unless record.persisted?
|
90
91
|
record.instance_eval do
|
91
92
|
write_attribute column, current_time
|
92
93
|
@changed_attributes.except!(*changes.keys)
|
@@ -33,8 +33,13 @@ module ActiveRecord
|
|
33
33
|
@records.map { |attrs, records| [attrs, records.group_by(&:class)] }
|
34
34
|
end
|
35
35
|
|
36
|
+
# There are more records as long as there is at least one record that is persisted
|
36
37
|
def more_records?
|
37
|
-
@records.
|
38
|
+
@records.each do |_, set|
|
39
|
+
set.each { |record| return true if record.persisted? } # will shortcut on first persisted record found
|
40
|
+
end
|
41
|
+
|
42
|
+
false # no persisted records found, so no more records to process
|
38
43
|
end
|
39
44
|
|
40
45
|
def add_record(record, *columns)
|
@@ -48,7 +53,6 @@ module ActiveRecord
|
|
48
53
|
@records.clear
|
49
54
|
@already_updated_records.clear
|
50
55
|
end
|
51
|
-
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
@@ -173,6 +173,30 @@ describe Activerecord::DelayTouching do
|
|
173
173
|
|
174
174
|
end
|
175
175
|
|
176
|
+
context 'persistence fails and rolls back transaction' do
|
177
|
+
|
178
|
+
it 'does not infinitely loop' do
|
179
|
+
updates = 0
|
180
|
+
allow(ActiveRecord::Base.connection).to receive(:update).and_wrap_original do |m, *args|
|
181
|
+
updates = updates + 1
|
182
|
+
raise StandardError, 'Too many updates - likely infinite loop detected' if updates > 1
|
183
|
+
|
184
|
+
m.call(*args)
|
185
|
+
end
|
186
|
+
|
187
|
+
ActiveRecord::Base.delay_touching do
|
188
|
+
ActiveRecord::Base.transaction do
|
189
|
+
# write and touch any new record
|
190
|
+
record = Post.create!
|
191
|
+
record.touch
|
192
|
+
raise ActiveRecord::Rollback
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
176
200
|
def expect_updates(tables)
|
177
201
|
expected_sql = tables.map do |entry|
|
178
202
|
if entry.kind_of?(Hash)
|
metadata
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-delay_touching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- GoDaddy P&C Commerce
|
7
8
|
- Brian Morearty
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activerecord
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- - "
|
18
|
+
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '4.2'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- - "
|
25
|
+
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '4.2'
|
27
28
|
- !ruby/object:Gem::Dependency
|
@@ -86,14 +87,14 @@ dependencies:
|
|
86
87
|
requirements:
|
87
88
|
- - "~>"
|
88
89
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
+
version: '3.0'
|
90
91
|
type: :development
|
91
92
|
prerelease: false
|
92
93
|
version_requirements: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
95
|
- - "~>"
|
95
96
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
97
|
+
version: '3.0'
|
97
98
|
- !ruby/object:Gem::Dependency
|
98
99
|
name: simplecov
|
99
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +141,7 @@ description: Batch up your ActiveRecord "touch" operations for better performanc
|
|
140
141
|
ActiveRecord::Base.delay_touching do ... end. When "end" is reached, all accumulated
|
141
142
|
"touch" calls will be consolidated into as few database round trips as possible.
|
142
143
|
email:
|
144
|
+
- nemo-engg@godaddy.com
|
143
145
|
- brian@morearty.org
|
144
146
|
executables: []
|
145
147
|
extensions: []
|
@@ -180,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
182
|
version: '0'
|
181
183
|
requirements: []
|
182
184
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.7.6
|
184
186
|
signing_key:
|
185
187
|
specification_version: 4
|
186
188
|
summary: Batch up your ActiveRecord "touch" operations for better performance.
|