From 24a148b18176b5d8eec4bc9838b7a76e172cc401 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 24 Mar 2025 00:01:18 +0100 Subject: [PATCH 1/2] Fix moving points on the map --- .app_version | 2 +- CHANGELOG.md | 6 ++++++ app/controllers/api/v1/points_controller.rb | 2 +- app/javascript/controllers/maps_controller.js | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.app_version b/.app_version index 3d9dcb1b..35aa2f3c 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.25.3 +0.25.4 diff --git a/CHANGELOG.md b/CHANGELOG.md index e90314c1..10f5c357 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +# 0.25.4 - 2025-03-24 + +## Fixed + +- Moving points on the map now works correctly. #957 + # 0.25.3 - 2025-03-22 ## Fixed diff --git a/app/controllers/api/v1/points_controller.rb b/app/controllers/api/v1/points_controller.rb index dc34387c..8eddebf6 100644 --- a/app/controllers/api/v1/points_controller.rb +++ b/app/controllers/api/v1/points_controller.rb @@ -32,7 +32,7 @@ class Api::V1::PointsController < ApiController def update point = current_api_user.tracked_points.find(params[:id]) - point.update(point_params) + point.update(lonlat: "POINT(#{point_params[:longitude]} #{point_params[:latitude]})") render json: point_serializer.new(point).call end diff --git a/app/javascript/controllers/maps_controller.js b/app/javascript/controllers/maps_controller.js index a74aaac3..a93affb4 100644 --- a/app/javascript/controllers/maps_controller.js +++ b/app/javascript/controllers/maps_controller.js @@ -501,10 +501,11 @@ export default class extends BaseController { } deletePoint(id, apiKey) { - fetch(`/api/v1/points/${id}?api_key=${apiKey}`, { + fetch(`/api/v1/points/${id}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', + 'Authorization': `Bearer ${apiKey}` } }) .then(response => { From 5335c912c39c612cb22b3e08d7ba5f2c950d3d96 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 24 Mar 2025 18:56:58 +0100 Subject: [PATCH 2/2] Update the rake task to also reindex the points table. --- CHANGELOG.md | 1 + app/views/home/index.html.erb | 2 +- lib/tasks/points.rake | 28 +++++++++++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f5c357..9e20159c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Fixed - Moving points on the map now works correctly. #957 +- `rake points:migrate_to_lonlat` task now also reindexes the points table. # 0.25.3 - 2025-03-22 diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 606d4c0d..9b223f40 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,6 +1,6 @@
-
+

diff --git a/lib/tasks/points.rake b/lib/tasks/points.rake index 1dc141c6..64c73ecd 100644 --- a/lib/tasks/points.rake +++ b/lib/tasks/points.rake @@ -5,15 +5,25 @@ namespace :points do task migrate_to_lonlat: :environment do puts 'Updating points to use lonlat...' - # Use PostGIS functions to properly create geography type - result = ActiveRecord::Base.connection.execute(<<~SQL) - UPDATE points - SET lonlat = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography - WHERE lonlat IS NULL - AND longitude IS NOT NULL - AND latitude IS NOT NULL; - SQL + ActiveRecord::Base.connection.execute('REINDEX TABLE points;') - puts "Successfully updated #{result.cmd_tuples} points with lonlat values" + ActiveRecord::Base.transaction do + ActiveRecord::Base.connection.execute('ALTER TABLE points DISABLE TRIGGER ALL;') + + # Update the data + result = ActiveRecord::Base.connection.execute(<<~SQL) + UPDATE points + SET lonlat = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography + WHERE lonlat IS NULL + AND longitude IS NOT NULL + AND latitude IS NOT NULL; + SQL + + ActiveRecord::Base.connection.execute('ALTER TABLE points ENABLE TRIGGER ALL;') + + puts "Successfully updated #{result.cmd_tuples} points with lonlat values" + end + + ActiveRecord::Base.connection.execute('ANALYZE points;') end end