snail_trail 1.1.0.rc.pre.3 → 1.1.0.rc.pre.5
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 +4 -4
- data/CHANGELOG.adoc +1 -0
- data/lib/snail_trail/events/base.rb +1 -1
- data/lib/snail_trail/frameworks/cucumber.rb +1 -0
- data/lib/snail_trail/frameworks/rspec.rb +1 -0
- data/lib/snail_trail/model_config.rb +2 -2
- data/lib/snail_trail/record_trail.rb +10 -0
- data/lib/snail_trail/request.rb +9 -6
- data/lib/snail_trail/version_concern.rb +1 -1
- data/lib/snail_trail/version_number.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9ea197550538c0a638d1a91ce2dff9180c174fc4192dc1e79db23b2dd42ee8
|
4
|
+
data.tar.gz: 25cffdd0fe4bec2c8d055439c93c8f9ea62fd004713958bf199adf85e96226dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6229102f9b61023f51180e9474f6a845cf4d4cb86a292a064ef266b86cb08381bd6d51fc76493c903ff0991be0a05988bd4594bc4bd968a161b001c94c0b1d5
|
7
|
+
data.tar.gz: 646c74ea4263ac65736f1ce1247dc2d177632435fbe4302af622de69471bbc50fa156d7eea87436e7ded879c7badb8a12e2645d8f77064b9d1854b771235b55f
|
data/CHANGELOG.adoc
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
* Add ``performance_mode!``
|
4
4
|
** This will wait to ``INSERT`` all versions until the transaction has finished
|
5
5
|
** ``INSERT``s happen in batches of 1000 rows
|
6
|
+
** Called via ``SnailTrail.request.performance_mode!`` or ``before_action :set_snail_trail_performance_mode``
|
6
7
|
|
7
8
|
== 1.0.0
|
8
9
|
|
@@ -232,7 +232,7 @@ module SnailTrail
|
|
232
232
|
#
|
233
233
|
# @api private
|
234
234
|
def metadatum_from_model_method(event, method)
|
235
|
-
if event != "create" &&
|
235
|
+
if event != "create" && event != "batch_create" &&
|
236
236
|
@record.has_attribute?(method) &&
|
237
237
|
attribute_changed_in_latest_version?(method)
|
238
238
|
attribute_in_previous_version(method, false)
|
@@ -12,6 +12,7 @@ RSpec.configure do |config|
|
|
12
12
|
SnailTrail.enabled = false
|
13
13
|
SnailTrail.request.enabled = true
|
14
14
|
SnailTrail.request.whodunnit = nil
|
15
|
+
SnailTrail.request.performance_mode = nil
|
15
16
|
SnailTrail.request.controller_info = {} if defined?(Rails) && defined?(RSpec::Rails)
|
16
17
|
end
|
17
18
|
|
@@ -131,12 +131,12 @@ module SnailTrail
|
|
131
131
|
|
132
132
|
r.snail_trail.record_performance_data
|
133
133
|
|
134
|
-
::SnailTrail.request.
|
134
|
+
::SnailTrail.request.clear_performance_mode_data
|
135
135
|
end
|
136
136
|
|
137
137
|
@model_class.after_rollback do
|
138
138
|
::SnailTrail.request.clear_transaction_id
|
139
|
-
::SnailTrail.request.
|
139
|
+
::SnailTrail.request.clear_performance_mode_data
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -149,15 +149,23 @@ module SnailTrail
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
+
# When in `performance_mode?`, this will save the `performance_mode_data` array to the "versions" table
|
153
|
+
# In batches of 1_000
|
154
|
+
#
|
155
|
+
# @return [void]
|
156
|
+
#
|
152
157
|
def record_performance_data
|
153
158
|
return unless ::SnailTrail.request.performance_mode?
|
154
159
|
|
155
160
|
all_data = ::SnailTrail.request.performance_mode_data
|
161
|
+
|
156
162
|
first_data = all_data.shift
|
157
163
|
version = @record.class.snail_trail.version_class.create(first_data)
|
158
164
|
update_transaction_id(version)
|
165
|
+
|
159
166
|
all_data.each_slice(1_000) do |datas|
|
160
167
|
timestamp = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")
|
168
|
+
|
161
169
|
datas.each do |d|
|
162
170
|
add_transaction_id_to(d)
|
163
171
|
d[:created_at] = timestamp
|
@@ -165,10 +173,12 @@ module SnailTrail
|
|
165
173
|
end
|
166
174
|
|
167
175
|
sql = ["INSERT INTO #{version.class.table_name} (#{datas.first.keys.join(", ")}) VALUES"]
|
176
|
+
|
168
177
|
datas.map do |data|
|
169
178
|
values = data.map { |k, v| @record.class.connection.quote(v.is_a?(Hash) ? JSON.generate(v) : v) }
|
170
179
|
sql << "(#{values.join(", ")}),"
|
171
180
|
end
|
181
|
+
|
172
182
|
sql.last.chop!
|
173
183
|
|
174
184
|
@record.class.snail_trail.version_class.connection.execute(sql.join("\n"))
|
data/lib/snail_trail/request.rb
CHANGED
@@ -129,17 +129,20 @@ module SnailTrail
|
|
129
129
|
self.performance_mode = true
|
130
130
|
end
|
131
131
|
|
132
|
-
def
|
133
|
-
self.
|
134
|
-
|
132
|
+
def clear_performance_mode_data
|
133
|
+
self.performance_mode_data =
|
134
|
+
if performance_mode?
|
135
|
+
[]
|
136
|
+
end
|
135
137
|
end
|
136
138
|
|
137
139
|
def performance_mode= val
|
138
140
|
store[:performance_mode] = !!val
|
139
141
|
|
140
|
-
|
141
|
-
|
142
|
-
|
142
|
+
self.performance_mode_data =
|
143
|
+
if performance_mode?
|
144
|
+
[]
|
145
|
+
end
|
143
146
|
|
144
147
|
performance_mode?
|
145
148
|
end
|