File tree Expand file tree Collapse file tree 4 files changed +22
-14
lines changed Expand file tree Collapse file tree 4 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,9 @@ def read_multi(keys)
41
41
keys . each_slice ( MULTI_BATCH_SIZE ) . each do |keys_batch |
42
42
query = Arel . sql ( select_sql ( keys_batch ) , *key_hashes_for ( keys_batch ) )
43
43
44
- results . merge! ( connection . select_all ( query , "SolidCache::Entry Load" ) . cast_values ( attribute_types ) . to_h )
44
+ with_connection do |connection |
45
+ results . merge! ( connection . select_all ( query , "SolidCache::Entry Load" ) . cast_values ( attribute_types ) . to_h )
46
+ end
45
47
end
46
48
end
47
49
end
@@ -54,7 +56,9 @@ def delete_by_key(*keys)
54
56
end
55
57
56
58
def clear_truncate
57
- connection . truncate ( table_name )
59
+ with_connection do |connection |
60
+ connection . truncate ( table_name )
61
+ end
58
62
end
59
63
60
64
def clear_delete
@@ -91,7 +95,9 @@ def add_key_hash_and_byte_size(payloads)
91
95
end
92
96
93
97
def upsert_unique_by
94
- connection . supports_insert_conflict_target? ? :key_hash : nil
98
+ with_connection do |connection |
99
+ connection . supports_insert_conflict_target? ? :key_hash : nil
100
+ end
95
101
end
96
102
97
103
# This constructs and caches a SQL query for a given number of keys.
Original file line number Diff line number Diff line change @@ -14,14 +14,16 @@ def disable_instrumentation(&block)
14
14
end
15
15
16
16
def with_instrumenter ( instrumenter , &block )
17
- if connection . respond_to? ( :with_instrumenter )
18
- connection . with_instrumenter ( instrumenter , &block )
19
- else
20
- begin
21
- old_instrumenter , ActiveSupport ::IsolatedExecutionState [ :active_record_instrumenter ] = ActiveSupport ::IsolatedExecutionState [ :active_record_instrumenter ] , instrumenter
22
- block . call
23
- ensure
24
- ActiveSupport ::IsolatedExecutionState [ :active_record_instrumenter ] = old_instrumenter
17
+ with_connection do |connection |
18
+ if connection . respond_to? ( :with_instrumenter )
19
+ connection . with_instrumenter ( instrumenter , &block )
20
+ else
21
+ begin
22
+ old_instrumenter , ActiveSupport ::IsolatedExecutionState [ :active_record_instrumenter ] = ActiveSupport ::IsolatedExecutionState [ :active_record_instrumenter ] , instrumenter
23
+ block . call
24
+ ensure
25
+ ActiveSupport ::IsolatedExecutionState [ :active_record_instrumenter ] = old_instrumenter
26
+ end
25
27
end
26
28
end
27
29
end
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ class Engine < ::Rails::Engine
41
41
end
42
42
43
43
config . after_initialize do
44
- if SolidCache . configuration . encrypt? && Record . connection . adapter_name == "PostgreSQL" && Rails ::VERSION ::MAJOR <= 7
44
+ if SolidCache . configuration . encrypt? && Record . lease_connection . adapter_name == "PostgreSQL" && Rails ::VERSION ::MAJOR <= 7
45
45
raise \
46
46
"Cannot enable encryption for Solid Cache: in Rails 7, Active Record Encryption does not support " \
47
47
"encrypting binary columns on PostgreSQL"
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ def test_active_record_instrumention_expiry
106
106
end
107
107
108
108
def test_no_connections_uninstrumented
109
- ActiveRecord ::ConnectionAdapters ::ConnectionPool . any_instance . stubs ( connection ) . raises ( ActiveRecord ::StatementTimeout )
109
+ ActiveRecord ::ConnectionAdapters ::ConnectionPool . any_instance . stubs ( :with_connection ) . raises ( ActiveRecord ::StatementTimeout )
110
110
111
111
cache = lookup_store ( expires_in : 60 , active_record_instrumentation : false )
112
112
@@ -120,7 +120,7 @@ def test_no_connections_uninstrumented
120
120
end
121
121
122
122
def test_no_connections_instrumented
123
- ActiveRecord ::ConnectionAdapters ::ConnectionPool . any_instance . stubs ( connection ) . raises ( ActiveRecord ::StatementTimeout )
123
+ ActiveRecord ::ConnectionAdapters ::ConnectionPool . any_instance . stubs ( :with_connection ) . raises ( ActiveRecord ::StatementTimeout )
124
124
125
125
cache = lookup_store ( expires_in : 60 )
126
126
You can’t perform that action at this time.
0 commit comments