Merge pull request #52131 from fatkodima/remove-unneeded-with_connection

Fix more `with_connection` offences inside Active Record
This commit is contained in:
Jean Boussier 2024-06-17 08:07:15 +02:00 committed by GitHub
commit 5ef7f73c30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 18 deletions

@ -248,18 +248,16 @@ def _insert_record(connection, values, returning) # :nodoc:
im = Arel::InsertManager.new(arel_table)
with_connection do |c|
if values.empty?
im.insert(connection.empty_insert_statement_value(primary_key))
else
im.insert(values.transform_keys { |name| arel_table[name] })
end
connection.insert(
im, "#{self} Create", primary_key || false, primary_key_value,
returning: returning
)
if values.empty?
im.insert(connection.empty_insert_statement_value(primary_key))
else
im.insert(values.transform_keys { |name| arel_table[name] })
end
connection.insert(
im, "#{self} Create", primary_key || false, primary_key_value,
returning: returning
)
end
def _update_record(values, constraints) # :nodoc:

@ -105,12 +105,13 @@ def sanitize_sql_for_order(condition)
# sanitize_sql_hash_for_assignment({ status: nil, group_id: 1 }, "posts")
# # => "`posts`.`status` = NULL, `posts`.`group_id` = 1"
def sanitize_sql_hash_for_assignment(attrs, table)
c = connection
attrs.map do |attr, value|
type = type_for_attribute(attr)
value = type.serialize(type.cast(value))
"#{c.quote_table_name_for_assignment(table, attr)} = #{c.quote(value)}"
end.join(", ")
with_connection do |c|
attrs.map do |attr, value|
type = type_for_attribute(attr)
value = type.serialize(type.cast(value))
"#{c.quote_table_name_for_assignment(table, attr)} = #{c.quote(value)}"
end.join(", ")
end
end
# Sanitizes a +string+ so that it is safe to use within an SQL

@ -34,7 +34,8 @@ def delete_version(version)
end
def delete_all_versions
@pool.with_connection do |connection|
# Eagerly check in connection to avoid checking in/out many times in the called method.
@pool.with_connection do
versions.each do |version|
delete_version(version)
end