From e6f74fc6abda32fff4c206aae65d3ebd1786bd01 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 13 Sep 2025 18:54:02 +0200 Subject: [PATCH] Update query to use lonlat column for bounds calculation --- app/models/stat.rb | 7 ++++--- app/views/shared/_sharing_modal.html.erb | 2 +- config/routes.rb | 3 --- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/models/stat.rb b/app/models/stat.rb index 4a2caebc..bca5a455 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -97,11 +97,12 @@ class Stat < ApplicationRecord return nil if point_count.zero? bounds_result = ActiveRecord::Base.connection.exec_query( - "SELECT MIN(latitude) as min_lat, MAX(latitude) as max_lat, - MIN(longitude) as min_lng, MAX(longitude) as max_lng + "SELECT MIN(ST_Y(lonlat::geometry)) as min_lat, MAX(ST_Y(lonlat::geometry)) as max_lat, + MIN(ST_X(lonlat::geometry)) as min_lng, MAX(ST_X(lonlat::geometry)) as max_lng FROM points WHERE user_id = $1 - AND timestamp BETWEEN $2 AND $3", + AND timestamp BETWEEN $2 AND $3 + AND lonlat IS NOT NULL", 'data_bounds_query', [user.id, start_date.to_i, end_date.to_i] ).first diff --git a/app/views/shared/_sharing_modal.html.erb b/app/views/shared/_sharing_modal.html.erb index e323535c..beb120d0 100644 --- a/app/views/shared/_sharing_modal.html.erb +++ b/app/views/shared/_sharing_modal.html.erb @@ -59,7 +59,7 @@ readonly class="input input-bordered join-item flex-1" data-sharing-modal-target="sharingLink" - value="<%= @stat.sharing_enabled? ? public_stat_url(@stat.sharing_uuid) : '' %>" /> + value="<%= @stat.sharing_enabled? ? shared_stat_url(@stat.sharing_uuid) : '' %>" />