Skip to content

Commit ae77151

Browse files
committed
Eliminate lease_connection call in Arel
1 parent 6dd1929 commit ae77151

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

activerecord/lib/arel/nodes/node.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ def invert
147147
# Maybe we should just use `Table.engine`? :'(
148148
def to_sql(engine = Table.engine)
149149
collector = Arel::Collectors::SQLString.new
150-
collector = engine.lease_connection.visitor.accept self, collector
151-
collector.value
150+
engine.with_connection do |connection|
151+
connection.visitor.accept(self, collector).value
152+
end
152153
end
153154

154155
def fetch_attribute

activerecord/lib/arel/tree_manager.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def to_dot
5252

5353
def to_sql(engine = Table.engine)
5454
collector = Arel::Collectors::SQLString.new
55-
collector = engine.lease_connection.visitor.accept @ast, collector
56-
collector.value
55+
engine.with_connection do |connection|
56+
engine.lease_connection.visitor.accept(@ast, collector).value
57+
end
5758
end
5859

5960
def initialize_copy(other)

activerecord/test/cases/arel/support/fake_record.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def initialize
129129
@connection_pool = ConnectionPool.new
130130
end
131131

132+
def with_connection(...)
133+
connection_pool.with_connection(...)
134+
end
135+
132136
def lease_connection
133137
connection_pool.lease_connection
134138
end

0 commit comments

Comments
 (0)