Skip to content

Commit

Permalink
Use trace instead of gpx_id in queries
Browse files Browse the repository at this point in the history
This makes the queries easier to read.
  • Loading branch information
gravitystorm committed Aug 30, 2023
1 parent f5db9cb commit b595b87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions app/models/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def import
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
Expand Down Expand Up @@ -242,10 +242,10 @@ def import
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
Expand Down
6 changes: 3 additions & 3 deletions test/models/trace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ def test_import_removes_previous_tracepoints

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
Expand Down

0 comments on commit b595b87

Please sign in to comment.