Merge remote-tracking branch 'upstream/pull/2131'
This commit is contained in:
commit
37f8f8a28c
5 changed files with 36 additions and 13 deletions
1
Gemfile
1
Gemfile
|
@ -46,6 +46,7 @@ gem "image_optim_rails"
|
||||||
# Load rails plugins
|
# Load rails plugins
|
||||||
gem "actionpack-page_caching"
|
gem "actionpack-page_caching"
|
||||||
gem "active_record_union"
|
gem "active_record_union"
|
||||||
|
gem "activerecord-import"
|
||||||
gem "cancancan"
|
gem "cancancan"
|
||||||
gem "composite_primary_keys", "~> 11.1.0"
|
gem "composite_primary_keys", "~> 11.1.0"
|
||||||
gem "config"
|
gem "config"
|
||||||
|
|
|
@ -40,6 +40,8 @@ GEM
|
||||||
activemodel (= 5.2.2.1)
|
activemodel (= 5.2.2.1)
|
||||||
activesupport (= 5.2.2.1)
|
activesupport (= 5.2.2.1)
|
||||||
arel (>= 9.0)
|
arel (>= 9.0)
|
||||||
|
activerecord-import (0.28.1)
|
||||||
|
activerecord (>= 3.2)
|
||||||
activestorage (5.2.2.1)
|
activestorage (5.2.2.1)
|
||||||
actionpack (= 5.2.2.1)
|
actionpack (= 5.2.2.1)
|
||||||
activerecord (= 5.2.2.1)
|
activerecord (= 5.2.2.1)
|
||||||
|
@ -423,6 +425,7 @@ DEPENDENCIES
|
||||||
aasm
|
aasm
|
||||||
actionpack-page_caching
|
actionpack-page_caching
|
||||||
active_record_union
|
active_record_union
|
||||||
|
activerecord-import
|
||||||
annotate
|
annotate
|
||||||
autoprefixer-rails (~> 8.6.3)
|
autoprefixer-rails (~> 8.6.3)
|
||||||
better_errors
|
better_errors
|
||||||
|
|
|
@ -289,7 +289,11 @@ class Trace < ActiveRecord::Base
|
||||||
# If there are any existing points for this trace then delete them
|
# If there are any existing points for this trace then delete them
|
||||||
Tracepoint.where(:gpx_id => id).delete_all
|
Tracepoint.where(:gpx_id => id).delete_all
|
||||||
|
|
||||||
gpx.points do |point|
|
gpx.points.each_slice(1_000) do |points|
|
||||||
|
# Gather the trace points together for a bulk import
|
||||||
|
tracepoints = []
|
||||||
|
|
||||||
|
points.each do |point|
|
||||||
if first
|
if first
|
||||||
f_lat = point.latitude
|
f_lat = point.latitude
|
||||||
f_lon = point.longitude
|
f_lon = point.longitude
|
||||||
|
@ -303,7 +307,16 @@ class Trace < ActiveRecord::Base
|
||||||
tp.timestamp = point.timestamp
|
tp.timestamp = point.timestamp
|
||||||
tp.gpx_id = id
|
tp.gpx_id = id
|
||||||
tp.trackid = point.segment
|
tp.trackid = point.segment
|
||||||
tp.save!
|
tracepoints << tp
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run the before_save and before_create callbacks, and then import them in bulk with activerecord-import
|
||||||
|
tracepoints.each do |tp|
|
||||||
|
tp.run_callbacks(:save) { false }
|
||||||
|
tp.run_callbacks(:create) { false }
|
||||||
|
end
|
||||||
|
|
||||||
|
Tracepoint.import!(tracepoints)
|
||||||
end
|
end
|
||||||
|
|
||||||
if gpx.actual_points.positive?
|
if gpx.actual_points.positive?
|
||||||
|
|
|
@ -13,6 +13,8 @@ module GPX
|
||||||
end
|
end
|
||||||
|
|
||||||
def points
|
def points
|
||||||
|
return enum_for(:points) unless block_given?
|
||||||
|
|
||||||
@possible_points = 0
|
@possible_points = 0
|
||||||
@actual_points = 0
|
@actual_points = 0
|
||||||
@tracksegs = 0
|
@tracksegs = 0
|
||||||
|
|
|
@ -206,6 +206,10 @@ class TraceTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
trace.reload
|
trace.reload
|
||||||
assert_equal 1, Tracepoint.where(:gpx_id => trace.id).count
|
assert_equal 1, Tracepoint.where(:gpx_id => trace.id).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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue