From b108c1f13391621df99382bb992776c999572970 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Dieguez Date: Thu, 31 Jan 2019 17:58:03 +0100 Subject: [PATCH] Patch for load times with pg_type loading in AR - See https://github.com/CartoDB/cartodb/issues/14615 - See https://github.com/rails/rails/issues/19578 --- .../zz_patch_activerecord_type_loading.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 config/initializers/zz_patch_activerecord_type_loading.rb diff --git a/config/initializers/zz_patch_activerecord_type_loading.rb b/config/initializers/zz_patch_activerecord_type_loading.rb new file mode 100644 index 000000000000..0f45002bb10d --- /dev/null +++ b/config/initializers/zz_patch_activerecord_type_loading.rb @@ -0,0 +1,23 @@ +module ActiveRecord + module ConnectionAdapters + module PostgreSQL + module OID # :nodoc: + class TypeMapInitializer # :nodoc: + def query_conditions_for_initial_load(type_map) + known_type_names = type_map.keys.map { |n| "'#{n}'" } + known_type_types = %w('r' 'e' 'd') + <<-SQL % [known_type_names.join(", "), known_type_types.join(", ")] + LEFT JOIN pg_type as tt ON (tt.typtype = 'c' AND tt.typarray = t.oid AND tt.typinput = 'record_in(cstring,oid,integer)'::regprocedure) + WHERE + tt.oid is null + AND (t.typname IN (%s) + OR t.typtype IN (%s) + OR t.typinput = 'array_in(cstring,oid,integer)'::regprocedure + OR t.typelem != 0) + SQL + end + end + end + end + end +end