diff --git a/NEWS.md b/NEWS.md index 553cdd0b8c..576791cda9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,7 @@ Development - Fix kepler.gl link in Maps section ([#15644](https://github.com/CartoDB/cartodb/issues/15644)) - /api/v3/me endpoint returns less public data ([#5627](https://github.com/CartoDB/cartodb-platform/issues/5627)) - Retrieve IPs before adding or removing to avoid inconsistencies ([#15643](https://github.com/CartoDB/cartodb/pull/15643)) +- Faster geometry types calculation for big datasets ([#15654](https://github.com/CartoDB/cartodb/pull/15654)) - Return error for requests whose authentication was succeeding with an expired session ([#15637](https://github.com/CartoDB/cartodb/pull/15637)) 4.37.0 (2020-04-24) diff --git a/app/models/table.rb b/app/models/table.rb index 388addc48d..497153aec1 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -1288,17 +1288,23 @@ class Table def query_geometry_types # We do not query the DB, if the_geom does not exist we just recover - begin - owner.in_database[ %Q{ - SELECT DISTINCT ST_GeometryType(the_geom) FROM ( + owner.in_database[distinct_geometry_sql].all.map { |r| r[:st_geometrytype] } + rescue StandardError + [] + end + + def distinct_geometry_sql + %{ + SELECT DISTINCT ST_GeometryType(the_geom) FROM ( + SELECT the_geom + FROM ( SELECT the_geom - FROM #{qualified_table_name} - WHERE (the_geom is not null) LIMIT 10 - ) as foo - }].all.map {|r| r[:st_geometrytype] } - rescue - [] - end + FROM #{qualified_table_name} + LIMIT 10000 + ) as limited + WHERE (the_geom is not null) LIMIT 10 + ) as not_null + } end def cache