super_settings 2.1.1 → 2.2.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c245924ff453f5cd0bde098003e6dc05d54b21aba4a42ddaf7c614c63233a542
4
- data.tar.gz: fb8672624d5c688794f8492be263534ed4e46ac49684f76d9bbf3bd120b62579
3
+ metadata.gz: 967d15a431f463f295d1585a1db0f7891e1eca3e16096890d829559b232d3870
4
+ data.tar.gz: 241ee0184528a02900ed05f2d21ac734bbfd635411fbe398bf694392d057cb08
5
5
  SHA512:
6
- metadata.gz: 605db9f00bbd1865203caaf7515c3d5f1ad83911653dd9410c69344dda0b21b8e58167806186969a6d2b27d4867a61d97b29333715c3f139741f16a3d3b0a635
7
- data.tar.gz: b1565e3ace970a26a8d126ec27e3bee6786b5da85e33e25bbde5a947af12e8067a23d143870b7012dd449b86ab5658fbeb99fb365bc8f738276cf8672ffc318d
6
+ metadata.gz: 682426a9592f6aa9bc2694dc38de649f4f31a714866298b59930c0ae81f1381eeafcd7faeb81e22288c71a0ba5edca4eb660c1f2bd04dd87cb872c5e434be0d3
7
+ data.tar.gz: ac71245f56b5b4694906a8d8d36528a9b814b2af15ac544a11f8a009636d62aa1c235b22700bfdb1f73283fa9cdaad3bcd335e590ddbac228669794f7267e61c
data/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ 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
+
13
+ ## 2.1.2
14
+
15
+ ### Fixed
16
+
17
+ - Fixed ActiveRecord code ensure there are connections to the database before attempting to checkout a connection to avoid errors when the database is not available.
18
+
7
19
  ## 2.1.1
8
20
 
9
21
  ### Fixed
data/README.md CHANGED
@@ -393,12 +393,10 @@ bundle exec rackup
393
393
 
394
394
  By default this will use Redis for storage using the default Redis URL. You can change the storage engine with the `STORAGE` environment variable.
395
395
 
396
- - `active_record` - Use the ActiveRecord storage engine.
397
396
  - `redis` - Use the Redis storage engine. The Redis URL can be set with the `REDIS_URL` environment variable.
398
397
  - `http` - Use the HTTP storage engine. The URL for the REST API can be set with the `REST_API_URL` environment variable.
399
398
  - `s3` - Use the S3 storage engine. The S3 URL can be set with the `S3_URL` environment variable.
400
399
  - `mongodb` - Use the MongoDB storage engine. The MongoDB URL can be set with the `MONGODB_URL` environment variable.
401
- - `null` - Use the null storage engine. This storage engine does not store settings at all.
402
400
 
403
401
  You can bring up all of these storage engines locally with the included docker-compose configuration.
404
402
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
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
@@ -57,15 +57,23 @@ module SuperSettings
57
57
  end
58
58
 
59
59
  def with_connection(&block)
60
- Model.connection_pool.with_connection(&block)
60
+ if Model.available?
61
+ Model.connection_pool.with_connection(&block)
62
+ else
63
+ yield
64
+ end
61
65
  end
62
66
 
63
67
  def transaction(&block)
64
- Model.transaction(&block)
68
+ if Model.available?
69
+ Model.transaction(&block)
70
+ else
71
+ yield
72
+ end
65
73
  end
66
74
 
67
75
  def destroy_all
68
- ApplicationRecord.transaction do
76
+ Model.transaction do
69
77
  Model.delete_all
70
78
  HistoryModel.delete_all
71
79
  end
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.1
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-02 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