Skip to content

Commit

Permalink
Combined calls to with_connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 7, 2024
1 parent 8a8c95a commit 29189ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/neighbor/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def self.neighbor_attributes

distance = distance.to_s

quoted_attribute = connection_pool.with_connection { |c| "#{c.quote_table_name(table_name)}.#{c.quote_column_name(attribute_name)}" }

column_info = columns_hash[attribute_name.to_s]
column_type = column_info&.type

Expand All @@ -113,7 +111,12 @@ def self.neighbor_attributes
Neighbor::Utils.validate(vector, dimensions: dimensions, type: type || Utils.type(adapter, column_info&.type), adapter: adapter)
vector = Neighbor::Utils.normalize(vector, column_info: column_info) if normalize

query = connection_pool.with_connection { |c| c.quote(column_attribute.serialize(vector)) }
quoted_attribute = nil
query = nil
connection_pool.with_connection do |c|
quoted_attribute = "#{c.quote_table_name(table_name)}.#{c.quote_column_name(attribute_name)}"
query = c.quote(column_attribute.serialize(vector))
end

if !precision.nil?
if adapter != :postgresql || column_type != :vector
Expand Down

0 comments on commit 29189ab

Please sign in to comment.