solid_cache 1.0.1 → 1.0.2

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: 0ef3fc7a701fc5af744a290377eae445564a040ccb938e2ea64caf1bab5e90da
4
- data.tar.gz: dffd9ee1ab8ea5f6f96620dfcaba35092bd7d5fd9ff5bed210271666e2b839fe
3
+ metadata.gz: d8807bd93a8e16495e40542655163d95bcfac3b9a0d96de0ccbea687899ba600
4
+ data.tar.gz: 15107cc9ed202a7c8cf01d962c7ec8182eed76c3677e86155f104fac07eae6b2
5
5
  SHA512:
6
- metadata.gz: 22441a9d3132510beff5347788844f6bb05a7da369220ccdc2228587aabb8c2cd51dfb81eecff7ffc0febc0d8b1dea2f1ed852e6393e2a7bfa0af01418913d2a
7
- data.tar.gz: 83b296209289d1399ac3b2b3857b6b2740d7d1da6e51f43ef9873e77179681ee65e05f6ca50afd9c10f0605279df637fa8ef8ba7dedd0f4b6a19349aa086c553
6
+ metadata.gz: 2c1bdc5f7ae9313d017388821a1792228b9ff59d9570cc46129f2b0127648aeda3e103b3f387758c37b4119010929f48452def1638dad43a90cb46d201db2274
7
+ data.tar.gz: a0352691be83a3ee2227c501235bfd7c8639ea08b717c0bcbfcf002a3901b367c142d430677afd30778cafef0918192ed4afc987b9082987524dbdc327d6e42b
data/Rakefile CHANGED
@@ -36,7 +36,7 @@ end
36
36
  configs.each do |config|
37
37
  namespace :test do
38
38
  task config do
39
- if config.to_s.start_with?("encrypted") && ENV["TARGET_DB"] == "postgres"
39
+ if config.to_s.start_with?("encrypted") && ENV["TARGET_DB"] == "postgres" && Rails::VERSION::MAJOR <= 7
40
40
  puts "Skipping encrypted tests on PostgreSQL as binary encrypted columns are not supported by Rails yet"
41
41
  next
42
42
  end
@@ -33,7 +33,9 @@ module SolidCache
33
33
 
34
34
  def read_multi(keys)
35
35
  without_query_cache do
36
- find_by_sql([select_sql(keys), *key_hashes_for(keys)]).pluck(:key, :value).to_h
36
+ query = Arel.sql(select_sql(keys), *key_hashes_for(keys))
37
+
38
+ connection.select_all(query, "SolidCache::Entry Load").cast_values(attribute_types).to_h
37
39
  end
38
40
  end
39
41
 
@@ -84,13 +86,24 @@ module SolidCache
84
86
  connection.supports_insert_conflict_target? ? :key_hash : nil
85
87
  end
86
88
 
89
+ # This constructs and caches a SQL query for a given number of keys.
90
+ #
91
+ # The query is constructed with two bind parameters to generate an IN (...) condition,
92
+ # which is then replaced with the correct amount based on the number of keys. The
93
+ # parameters are filled later when executing the query. This is done through Active Record
94
+ # to ensure the field and table names are properly quoted and escaped based on the used database adapter.
95
+
96
+ # For example: The query for 4 keys will be transformed from:
97
+ # > SELECT "key", "value" FROM "solid_cache_entries" WHERE "key_hash" IN (1111, 2222)
98
+ # into:
99
+ # > SELECT "key", "value" FROM "solid_cache_entries" WHERE "key_hash" IN (?, ?, ?, ?)
87
100
  def select_sql(keys)
88
- @get_sql ||= {}
89
- @get_sql[keys.count] ||= \
90
- where(key_hash: [ "1111", "2222" ])
101
+ @select_sql ||= {}
102
+ @select_sql[keys.count] ||= \
103
+ where(key_hash: [ 1111, 2222 ])
91
104
  .select(:key, :value)
92
105
  .to_sql
93
- .gsub("1111, 2222", (["?"] * keys.count).join(", "))
106
+ .gsub("1111, 2222", Array.new(keys.count, "?").join(", "))
94
107
  end
95
108
 
96
109
  def key_hash_for(key)
@@ -37,9 +37,9 @@ module SolidCache
37
37
  end
38
38
 
39
39
  config.after_initialize do
40
- if SolidCache.configuration.encrypt? && SolidCache::Record.connection.adapter_name == "PostgreSQL"
40
+ if SolidCache.configuration.encrypt? && Record.connection.adapter_name == "PostgreSQL" && Rails::VERSION::MAJOR <= 7
41
41
  raise \
42
- "Cannot enable encryption for Solid Cache: Active Record Encryption does not currently support " \
42
+ "Cannot enable encryption for Solid Cache: in Rails 7, Active Record Encryption does not support " \
43
43
  "encrypting binary columns on PostgreSQL"
44
44
  end
45
45
  end
@@ -15,11 +15,21 @@ module SolidCache
15
15
  end
16
16
 
17
17
  def increment(name, amount = 1, options = nil)
18
- adjust(name, amount, options)
18
+ options = merged_options(options)
19
+ key = normalize_key(name, options)
20
+
21
+ instrument :increment, key, amount: amount do
22
+ adjust(name, amount, options)
23
+ end
19
24
  end
20
25
 
21
26
  def decrement(name, amount = 1, options = nil)
22
- adjust(name, -amount, options)
27
+ options = merged_options(options)
28
+ key = normalize_key(name, options)
29
+
30
+ instrument :decrement, key, amount: amount do
31
+ adjust(name, -amount, options)
32
+ end
23
33
  end
24
34
 
25
35
  def cleanup(options = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCache
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donal McBreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-22 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord