Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Caching results from geometry_columns #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions lib/spatial_adapter/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,34 @@ 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
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 = {}
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
cache[table_name] = raw_geom_infos
end

raw_geom_infos
@raw_geom_infos_cache = cache
cache[table_name]
end
end

Expand Down