From d0572a65952eff779d01706b765c31b474a19e5a Mon Sep 17 00:00:00 2001 From: Don Pflaster Date: Fri, 22 Jun 2012 14:03:51 -0400 Subject: [PATCH 1/2] Creating cache so individual tables are only polled once --- lib/spatial_adapter/postgresql.rb | 42 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/spatial_adapter/postgresql.rb b/lib/spatial_adapter/postgresql.rb index f797b87..82e371f 100644 --- a/lib/spatial_adapter/postgresql.rb +++ b/lib/spatial_adapter/postgresql.rb @@ -213,29 +213,31 @@ def tables_without_postgis end def column_spatial_info(table_name) - constr = query("SELECT * FROM geometry_columns WHERE f_table_name = '#{table_name}'") - - raw_geom_infos = {} - constr.each do |constr_def_a| - raw_geom_infos[constr_def_a[3]] ||= SpatialAdapter::RawGeomInfo.new - raw_geom_infos[constr_def_a[3]].type = constr_def_a[6] - raw_geom_infos[constr_def_a[3]].dimension = constr_def_a[4].to_i - raw_geom_infos[constr_def_a[3]].srid = constr_def_a[5].to_i - - if raw_geom_infos[constr_def_a[3]].type[-1] == ?M - raw_geom_infos[constr_def_a[3]].with_m = true - raw_geom_infos[constr_def_a[3]].type.chop! - else - raw_geom_infos[constr_def_a[3]].with_m = false + if !@raw_geom_infos_cache[table_name] + constr = query("SELECT * FROM geometry_columns WHERE f_table_name = '#{table_name}'") + + raw_geom_infos = {} + constr.each do |constr_def_a| + raw_geom_infos[constr_def_a[3]] ||= SpatialAdapter::RawGeomInfo.new + raw_geom_infos[constr_def_a[3]].type = constr_def_a[6] + raw_geom_infos[constr_def_a[3]].dimension = constr_def_a[4].to_i + raw_geom_infos[constr_def_a[3]].srid = constr_def_a[5].to_i + + if raw_geom_infos[constr_def_a[3]].type[-1] == ?M + raw_geom_infos[constr_def_a[3]].with_m = true + raw_geom_infos[constr_def_a[3]].type.chop! + else + raw_geom_infos[constr_def_a[3]].with_m = false + end end - end - raw_geom_infos.each_value do |raw_geom_info| - #check the presence of z and m - raw_geom_info.convert! + raw_geom_infos.each_value do |raw_geom_info| + #check the presence of z and m + raw_geom_info.convert! + end + @raw_geom_infos_cache[table_name] = raw_geom_infos end - - raw_geom_infos + @raw_geom_infos_cache[table_name] end end From 8b6ca2e198e5c9f67eb14edacb906a3405e79e67 Mon Sep 17 00:00:00 2001 From: Don Pflaster Date: Fri, 22 Jun 2012 14:10:09 -0400 Subject: [PATCH 2/2] Updated caching logic for postgres --- lib/spatial_adapter/postgresql.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/spatial_adapter/postgresql.rb b/lib/spatial_adapter/postgresql.rb index 82e371f..2ab3b84 100644 --- a/lib/spatial_adapter/postgresql.rb +++ b/lib/spatial_adapter/postgresql.rb @@ -213,7 +213,9 @@ def tables_without_postgis end def column_spatial_info(table_name) - if !@raw_geom_infos_cache[table_name] + cache = @raw_geom_infos_cache ||= Hash.new + + if !cache[table_name] constr = query("SELECT * FROM geometry_columns WHERE f_table_name = '#{table_name}'") raw_geom_infos = {} @@ -235,9 +237,10 @@ def column_spatial_info(table_name) #check the presence of z and m raw_geom_info.convert! end - @raw_geom_infos_cache[table_name] = raw_geom_infos + cache[table_name] = raw_geom_infos end - @raw_geom_infos_cache[table_name] + @raw_geom_infos_cache = cache + cache[table_name] end end