super_settings 2.1.2 → 2.2.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
2
  SHA256:
3
- metadata.gz: ecd3fc92a5668536f7d1300641505730c603b2c539dc069469e8559b1fbda7c2
4
- data.tar.gz: c654d8ff805fda401c43b2df65a4f853330f5182398f7462f3d8954af4ae47e0
3
+ metadata.gz: 967d15a431f463f295d1585a1db0f7891e1eca3e16096890d829559b232d3870
4
+ data.tar.gz: 241ee0184528a02900ed05f2d21ac734bbfd635411fbe398bf694392d057cb08
5
5
  SHA512:
6
- metadata.gz: b97bc579ecce698c0080dab893456d36d5c3a7144695f07a13a03df1c1fb23df182c61155001066befc03922cbc945e35b43198d1d6e8fb0636faedc540bd2ce
7
- data.tar.gz: 690abe15783bb18ca0e71494140c9d554f6ae532542a734d3027911fe771e4e93b1fde67dde18558872885e5e9b9edca96bda6587ca351847674d725e544b3c7
6
+ metadata.gz: 682426a9592f6aa9bc2694dc38de649f4f31a714866298b59930c0ae81f1381eeafcd7faeb81e22288c71a0ba5edca4eb660c1f2bd04dd87cb872c5e434be0d3
7
+ data.tar.gz: ac71245f56b5b4694906a8d8d36528a9b814b2af15ac544a11f8a009636d62aa1c235b22700bfdb1f73283fa9cdaad3bcd335e590ddbac228669794f7267e61c
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 2.2.0
8
+
9
+ ### Changed
10
+
11
+ - After save callbacks are now called only after the transaction is committed and settings have been persisted to the data store. When updating multiple records the callbacks will be called after all changes have been persisted rather than immediatly after calling `save!` on each record.
12
+
7
13
  ## 2.1.2
8
14
 
9
15
  ### Fixed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.2.0
@@ -164,7 +164,7 @@ module SuperSettings
164
164
  all_valid, settings = update_settings(params, changed_by)
165
165
  if all_valid
166
166
  storage.with_connection do
167
- storage.transaction do
167
+ transaction do |_changes|
168
168
  settings.each do |setting|
169
169
  setting.save!
170
170
  end
@@ -202,6 +202,38 @@ module SuperSettings
202
202
  cache&.delete(Setting::LAST_UPDATED_CACHE_KEY)
203
203
  end
204
204
 
205
+ # Wrap a block of code in a transaction.
206
+ #
207
+ # @api private
208
+ def transaction(&block)
209
+ changes = Thread.current[:super_settings_transaction]
210
+ return yield if changes
211
+
212
+ changes = []
213
+ Thread.current[:super_settings_transaction] = changes
214
+
215
+ begin
216
+ @storage.transaction(&block)
217
+
218
+ clear_last_updated_cache
219
+
220
+ changes.each do |setting|
221
+ setting.send(:call_after_save_callbacks)
222
+ setting.send(:clear_changes)
223
+ end
224
+ ensure
225
+ Thread.current[:super_settings_transaction] = nil
226
+ end
227
+ end
228
+
229
+ # Add a record to the current transaction.
230
+ #
231
+ # @api private
232
+ def add_record_to_transaction(record)
233
+ changes = Thread.current[:super_settings_transaction]
234
+ changes << record if changes
235
+ end
236
+
205
237
  private
206
238
 
207
239
  # Updates settings in memory from an array of parameters.
@@ -454,17 +486,13 @@ module SuperSettings
454
486
  self.created_at ||= timestamp
455
487
  self.updated_at = timestamp if updated_at.nil? || !changed?(:updated_at)
456
488
 
489
+ return if @changes.empty?
490
+
457
491
  self.class.storage.with_connection do
458
- self.class.storage.transaction do
492
+ self.class.transaction do
459
493
  record_value_change
460
494
  @record.save!
461
- end
462
-
463
- begin
464
- self.class.clear_last_updated_cache
465
- call_after_save_callbacks
466
- ensure
467
- clear_changes
495
+ self.class.add_record_to_transaction(self)
468
496
  end
469
497
  end
470
498
  nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-03 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler