]> git.openstreetmap.org Git - rails.git/commitdiff
Use trace instead of gpx_id in queries
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 30 Aug 2023 15:51:44 +0000 (16:51 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 30 Aug 2023 16:08:46 +0000 (17:08 +0100)
This makes the queries easier to read.

app/models/trace.rb
test/models/trace_test.rb

index 35fee0bf4f800d7fd22f906d1b9cc3040ea5727f..2411fb9b7a3c56c2f2adc57787a6194f83058c51 100644 (file)
@@ -209,7 +209,7 @@ class Trace < ApplicationRecord
       first = true
 
       # If there are any existing points for this trace then delete them
-      Tracepoint.where(:gpx_id => id).delete_all
+      Tracepoint.where(:trace => id).delete_all
 
       gpx.points.each_slice(1_000) do |points|
         # Gather the trace points together for a bulk import
@@ -242,10 +242,10 @@ class Trace < ApplicationRecord
       end
 
       if gpx.actual_points.positive?
-        max_lat = Tracepoint.where(:gpx_id => id).maximum(:latitude)
-        min_lat = Tracepoint.where(:gpx_id => id).minimum(:latitude)
-        max_lon = Tracepoint.where(:gpx_id => id).maximum(:longitude)
-        min_lon = Tracepoint.where(:gpx_id => id).minimum(:longitude)
+        max_lat = Tracepoint.where(:trace => id).maximum(:latitude)
+        min_lat = Tracepoint.where(:trace => id).minimum(:latitude)
+        max_lon = Tracepoint.where(:trace => id).maximum(:longitude)
+        min_lon = Tracepoint.where(:trace => id).minimum(:longitude)
 
         max_lat = max_lat.to_f / 10000000
         min_lat = min_lat.to_f / 10000000
index 762df66484d185c82bc52f305e739a989421a1cc..66107771ae5a299c7155e0097add0ed06e8800cb 100644 (file)
@@ -193,16 +193,16 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_creates_tracepoints
     trace = create(:trace, :fixture => "a")
-    assert_equal 0, Tracepoint.where(:gpx_id => trace.id).count
+    assert_equal 0, Tracepoint.where(:trace => trace).count
 
     trace.import
 
     trace.reload
-    assert_equal 1, Tracepoint.where(:gpx_id => trace.id).count
+    assert_equal 1, Tracepoint.where(:trace => trace).count
 
     # Check that the tile has been set prior to the bulk import
     # i.e. that the callbacks have been run correctly
-    assert_equal 3221331576, Tracepoint.where(:gpx_id => trace.id).first.tile
+    assert_equal 3221331576, Tracepoint.where(:trace => trace).first.tile
   end
 
   def test_import_creates_icon