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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +0 -2
- data/VERSION +1 -1
- data/lib/super_settings/setting.rb +37 -9
- data/lib/super_settings/storage/active_record_storage.rb +11 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 967d15a431f463f295d1585a1db0f7891e1eca3e16096890d829559b232d3870
|
4
|
+
data.tar.gz: 241ee0184528a02900ed05f2d21ac734bbfd635411fbe398bf694392d057cb08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
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
|
-
|
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.
|
492
|
+
self.class.transaction do
|
459
493
|
record_value_change
|
460
494
|
@record.save!
|
461
|
-
|
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.
|
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.
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2024-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|