Skip to content

Commit

Permalink
Use a single query type map for all pg connections
Browse files Browse the repository at this point in the history
This should save memory compared to using a separate but identical
type map per connection.
  • Loading branch information
jeremyevans committed Jun 28, 2018
1 parent b5f7c39 commit 0ecf401
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/sequel/adapters/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
end

Sequel::Postgres::USES_PG = true
if defined?(PG::TypeMapByClass)
type_map = Sequel::Postgres::PG_QUERY_TYPE_MAP = PG::TypeMapByClass.new
type_map[Integer] = PG::TextEncoder::Integer.new
type_map[FalseClass] = type_map[TrueClass] = PG::TextEncoder::Boolean.new
type_map[Float] = PG::TextEncoder::Float.new
end
rescue LoadError => e
begin
require 'postgres-pr/postgres-compat'
Expand Down Expand Up @@ -211,12 +217,8 @@ def connect(server)
end

conn.instance_variable_set(:@db, self)
if USES_PG && conn.respond_to?(:type_map_for_queries=)
type_map = PG::TypeMapByClass.new
type_map[Integer] = PG::TextEncoder::Integer.new
type_map[FalseClass] = type_map[TrueClass] = PG::TextEncoder::Boolean.new
type_map[Float] = PG::TextEncoder::Float.new
conn.type_map_for_queries = type_map
if USES_PG && conn.respond_to?(:type_map_for_queries=) && defined?(PG_QUERY_TYPE_MAP)
conn.type_map_for_queries = PG_QUERY_TYPE_MAP
end

if encoding = opts[:encoding] || opts[:charset]
Expand Down

0 comments on commit 0ecf401

Please sign in to comment.