From c18b09181ea5d6a6a348332c04ae39ba19d6cd07 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 21 Jul 2025 22:45:57 +0200 Subject: [PATCH] Add index on places geodata osm id --- CHANGELOG.md | 1 + ...0250721204404_add_index_on_places_geodata_osm_id.rb | 10 ++++++++++ db/schema.rb | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250721204404_add_index_on_places_geodata_osm_id.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 04d1a143..0c244831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Fixed - Points limit exceeded check is now cached. +- Reverse geocoding for places is now significantly faster. # [0.30.0] - 2025-07-21 diff --git a/db/migrate/20250721204404_add_index_on_places_geodata_osm_id.rb b/db/migrate/20250721204404_add_index_on_places_geodata_osm_id.rb new file mode 100644 index 00000000..83359ec4 --- /dev/null +++ b/db/migrate/20250721204404_add_index_on_places_geodata_osm_id.rb @@ -0,0 +1,10 @@ +class AddIndexOnPlacesGeodataOsmId < ActiveRecord::Migration[8.0] + disable_ddl_transaction! + + def change + add_index :places, "(geodata->'properties'->>'osm_id')", + using: :btree, + name: 'index_places_on_geodata_osm_id', + algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 837c0927..402729b9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_07_03_193657) do +ActiveRecord::Schema[8.0].define(version: 2025_07_21_204404) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" enable_extension "postgis" @@ -77,6 +77,9 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_03_193657) do t.index ["name"], name: "index_countries_on_name" end + create_table "data_migrations", primary_key: "version", id: :string, force: :cascade do |t| + end + create_table "exports", force: :cascade do |t| t.string "name", null: false t.string "url" @@ -143,6 +146,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_03_193657) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.geography "lonlat", limit: {srid: 4326, type: "st_point", geographic: true} + t.index "(((geodata -> 'properties'::text) ->> 'osm_id'::text))", name: "index_places_on_geodata_osm_id" t.index ["lonlat"], name: "index_places_on_lonlat", using: :gist end