diff --git a/app/models/solid_cache/entry.rb b/app/models/solid_cache/entry.rb index c7b401f..16b92e8 100644 --- a/app/models/solid_cache/entry.rb +++ b/app/models/solid_cache/entry.rb @@ -70,13 +70,13 @@ def id_range private def upsert_all_no_query_cache(payloads) - insert_all = ActiveRecord::InsertAll.new( - self, - add_key_hash_and_byte_size(payloads), - unique_by: upsert_unique_by, - on_duplicate: :update, - update_only: upsert_update_only - ) + args = [ self, + connection_for_insert_all, + add_key_hash_and_byte_size(payloads) ].compact + options = { unique_by: upsert_unique_by, + on_duplicate: :update, + update_only: upsert_update_only } + insert_all = ActiveRecord::InsertAll.new(*args, **options) sql = connection.build_insert_sql(ActiveRecord::InsertAll::Builder.new(insert_all)) message = +"#{self} " @@ -86,6 +86,10 @@ def upsert_all_no_query_cache(payloads) connection.send exec_query_method, sql, message end + def connection_for_insert_all + Rails.version >= "7.2" ? connection : nil + end + def add_key_hash_and_byte_size(payloads) payloads.map do |payload| payload.dup.tap do |payload| diff --git a/gemfiles/rails_main.gemfile.lock b/gemfiles/rails_main.gemfile.lock index 0de7812..cb54585 100644 --- a/gemfiles/rails_main.gemfile.lock +++ b/gemfiles/rails_main.gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/rails/rails.git - revision: cb035bde4e4a09789792ba69117f602231c36584 + revision: 029d31ca31ab72df7bb79372f4ff057231fd0196 branch: main specs: actionpack (7.2.0.alpha) @@ -36,7 +36,7 @@ GIT connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) - minitest (>= 5.1) + minitest (>= 5.1, < 5.22.0) tzinfo (~> 2.0, >= 2.0.5) railties (7.2.0.alpha) actionpack (= 7.2.0.alpha) @@ -64,7 +64,7 @@ GEM thor (>= 0.14.0) ast (2.4.2) base64 (0.2.0) - bigdecimal (3.1.5) + bigdecimal (3.1.6) builder (3.2.4) concurrent-ruby (1.2.3) connection_pool (2.4.1) @@ -72,15 +72,14 @@ GEM debug (1.9.1) irb (~> 1.10) reline (>= 0.3.8) - drb (2.2.0) - ruby2_keywords + drb (2.2.1) erubi (1.12.0) globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.1) + i18n (1.14.4) concurrent-ruby (~> 1.0) - io-console (0.7.1) - irb (1.11.1) + io-console (0.7.2) + irb (1.12.0) rdoc reline (>= 0.4.2) json (2.7.1) @@ -88,25 +87,25 @@ GEM loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) - minitest (5.21.1) + minitest (5.21.2) mocha (2.1.0) ruby2_keywords (>= 0.0.5) mysql2 (0.5.5) - nokogiri (1.16.0-arm64-darwin) + nokogiri (1.16.2-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.0-x86_64-darwin) + nokogiri (1.16.2-x86_64-darwin) racc (~> 1.4) - nokogiri (1.16.0-x86_64-linux) + nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) parallel (1.24.0) - parser (3.3.0.4) + parser (3.3.0.5) ast (~> 2.4.1) racc - pg (1.5.4) + pg (1.5.6) psych (5.1.2) stringio racc (1.7.3) - rack (3.0.8) + rack (3.0.9.1) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -126,10 +125,10 @@ GEM rdoc (6.6.2) psych (>= 4.0.0) regexp_parser (2.9.0) - reline (0.4.2) + reline (0.4.3) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.60.0) + rubocop (1.62.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -137,14 +136,14 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) rubocop-md (1.2.2) rubocop (>= 1.0) - rubocop-minitest (0.34.4) + rubocop-minitest (0.34.5) rubocop (>= 1.39, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) rubocop-packaging (0.5.2) @@ -152,11 +151,11 @@ GEM rubocop-performance (1.20.2) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) - rubocop-rails (2.23.1) + rubocop-rails (2.24.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sprockets (4.2.1) @@ -166,18 +165,18 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.7.0-arm64-darwin) - sqlite3 (1.7.0-x86_64-darwin) - sqlite3 (1.7.0-x86_64-linux) + sqlite3 (1.7.2-arm64-darwin) + sqlite3 (1.7.2-x86_64-darwin) + sqlite3 (1.7.2-x86_64-linux) stringio (3.1.0) - thor (1.3.0) + thor (1.3.1) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) useragent (0.16.10) webrick (1.8.1) - zeitwerk (2.6.12) + zeitwerk (2.6.13) PLATFORMS arm64-darwin-21 diff --git a/test/unit/execution_test.rb b/test/unit/execution_test.rb index 79743ba..a86e8a1 100644 --- a/test/unit/execution_test.rb +++ b/test/unit/execution_test.rb @@ -108,7 +108,7 @@ def test_active_record_instrumention_expiry def test_no_connections_uninstrumented skip if multi_cluster? - ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(:connection).raises(ActiveRecord::StatementInvalid) + ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(connection).raises(ActiveRecord::StatementInvalid) cache = lookup_store(expires_in: 60, active_record_instrumentation: false) @@ -124,7 +124,7 @@ def test_no_connections_uninstrumented def test_no_connections_instrumented skip if multi_cluster? - ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(:connection).raises(ActiveRecord::StatementInvalid) + ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(connection).raises(ActiveRecord::StatementInvalid) cache = lookup_store(expires_in: 60) @@ -148,4 +148,9 @@ def report(error, handled:, severity:, context:, source: nil) errors << [ error, { context: context, handled: handled, level: severity, source: source } ] end end + + private + def connection + Rails.version >= "7.2" ? :lease_connection : :connection + end end