mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Fix failing specs
This commit is contained in:
parent
d4c0eaa549
commit
83fc3106a0
2 changed files with 4 additions and 36 deletions
|
|
@ -196,6 +196,7 @@ bundle exec bundle-audit # Dependency security
|
||||||
|
|
||||||
1. **Location Data**: Always handle location data with appropriate precision and privacy considerations
|
1. **Location Data**: Always handle location data with appropriate precision and privacy considerations
|
||||||
2. **PostGIS**: Leverage PostGIS features for geographic calculations rather than Ruby-based solutions
|
2. **PostGIS**: Leverage PostGIS features for geographic calculations rather than Ruby-based solutions
|
||||||
|
2.1 **Coordinates**: Use `lonlat` column in `points` table for geographic calculations
|
||||||
3. **Background Jobs**: Use Sidekiq for any potentially long-running operations
|
3. **Background Jobs**: Use Sidekiq for any potentially long-running operations
|
||||||
4. **Testing**: Include both unit and integration tests for location-based features
|
4. **Testing**: Include both unit and integration tests for location-based features
|
||||||
5. **Performance**: Consider database indexes for geographic queries
|
5. **Performance**: Consider database indexes for geographic queries
|
||||||
|
|
|
||||||
|
|
@ -6,42 +6,9 @@ module LocationSearch
|
||||||
# Using PostGIS for efficient spatial queries
|
# Using PostGIS for efficient spatial queries
|
||||||
end
|
end
|
||||||
|
|
||||||
# Debug method to test spatial queries directly
|
|
||||||
def debug_points_near(user, latitude, longitude, radius_meters = 1000)
|
|
||||||
query = <<~SQL
|
|
||||||
SELECT
|
|
||||||
p.id,
|
|
||||||
p.timestamp,
|
|
||||||
ST_Y(p.lonlat::geometry) as latitude,
|
|
||||||
ST_X(p.lonlat::geometry) as longitude,
|
|
||||||
p.city,
|
|
||||||
p.country,
|
|
||||||
ST_Distance(p.lonlat, ST_Point(#{longitude}, #{latitude})::geography) as distance_meters
|
|
||||||
FROM points p
|
|
||||||
WHERE p.user_id = #{user.id}
|
|
||||||
AND ST_DWithin(p.lonlat, ST_Point(#{longitude}, #{latitude})::geography, #{radius_meters})
|
|
||||||
ORDER BY distance_meters ASC
|
|
||||||
LIMIT 10;
|
|
||||||
SQL
|
|
||||||
|
|
||||||
puts "=== DEBUG SPATIAL QUERY ==="
|
|
||||||
puts "Searching for user #{user.id} near [#{latitude}, #{longitude}] within #{radius_meters}m"
|
|
||||||
puts "Query: #{query}"
|
|
||||||
|
|
||||||
results = ActiveRecord::Base.connection.exec_query(query)
|
|
||||||
puts "Found #{results.count} points:"
|
|
||||||
|
|
||||||
results.each do |row|
|
|
||||||
puts "- Point #{row['id']}: [#{row['latitude']}, #{row['longitude']}] - #{row['distance_meters'].to_f.round(2)}m away"
|
|
||||||
end
|
|
||||||
|
|
||||||
results
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_points_near(user, latitude, longitude, radius_meters, date_options = {})
|
def find_points_near(user, latitude, longitude, radius_meters, date_options = {})
|
||||||
points_query = build_spatial_query(user, latitude, longitude, radius_meters, date_options)
|
points_query = build_spatial_query(user, latitude, longitude, radius_meters, date_options)
|
||||||
|
|
||||||
# Execute query and return results with calculated distance
|
|
||||||
ActiveRecord::Base.connection.exec_query(points_query)
|
ActiveRecord::Base.connection.exec_query(points_query)
|
||||||
.map { |row| format_point_result(row) }
|
.map { |row| format_point_result(row) }
|
||||||
.sort_by { |point| point[:timestamp] }
|
.sort_by { |point| point[:timestamp] }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue