Skip to content

Commit

Permalink
Merge pull request #165 from higher-pixels/insert-all-breaking-change
Browse files Browse the repository at this point in the history
Addressing Rails Edge breaking change with insert_all
  • Loading branch information
djmb authored Mar 11, 2024
2 parents 85f1934 + 157639d commit 8bc68ce
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
18 changes: 11 additions & 7 deletions app/models/solid_cache/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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} "
Expand All @@ -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|
Expand Down
55 changes: 27 additions & 28 deletions gemfiles/rails_main.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/rails/rails.git
revision: cb035bde4e4a09789792ba69117f602231c36584
revision: 029d31ca31ab72df7bb79372f4ff057231fd0196
branch: main
specs:
actionpack (7.2.0.alpha)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -64,49 +64,48 @@ 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)
crass (1.0.6)
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)
language_server-protocol (3.17.0.3)
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)
Expand All @@ -126,37 +125,37 @@ 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)
parser (>= 3.3.0.2)
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)
rubocop (>= 1.33, < 2.0)
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)
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions test/unit/execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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

0 comments on commit 8bc68ce

Please sign in to comment.