Non-rigourous testing shows a significant speedup, even on ssds.
# Load rails plugins
gem "actionpack-page_caching"
gem "active_record_union"
# Load rails plugins
gem "actionpack-page_caching"
gem "active_record_union"
+gem "activerecord-import"
gem "cancancan"
gem "composite_primary_keys", "~> 11.1.0"
gem "config"
gem "cancancan"
gem "composite_primary_keys", "~> 11.1.0"
gem "config"
activemodel (= 5.2.2.1)
activesupport (= 5.2.2.1)
arel (>= 9.0)
activemodel (= 5.2.2.1)
activesupport (= 5.2.2.1)
arel (>= 9.0)
+ activerecord-import (0.28.1)
+ activerecord (>= 3.2)
activestorage (5.2.2.1)
actionpack (= 5.2.2.1)
activerecord (= 5.2.2.1)
activestorage (5.2.2.1)
actionpack (= 5.2.2.1)
activerecord (= 5.2.2.1)
aasm
actionpack-page_caching
active_record_union
aasm
actionpack-page_caching
active_record_union
annotate
autoprefixer-rails (~> 8.6.3)
better_errors
annotate
autoprefixer-rails (~> 8.6.3)
better_errors
# If there are any existing points for this trace then delete them
Tracepoint.where(:gpx_id => id).delete_all
# If there are any existing points for this trace then delete them
Tracepoint.where(:gpx_id => id).delete_all
+ # Gather the trace points together for a bulk import
+ tracepoints = []
gpx.points do |point|
if first
f_lat = point.latitude
gpx.points do |point|
if first
f_lat = point.latitude
tp.timestamp = point.timestamp
tp.gpx_id = id
tp.trackid = point.segment
tp.timestamp = point.timestamp
tp.gpx_id = id
tp.trackid = point.segment
+ # 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)
+
if gpx.actual_points.positive?
max_lat = Tracepoint.where(:gpx_id => id).maximum(:latitude)
min_lat = Tracepoint.where(:gpx_id => id).minimum(:latitude)
if gpx.actual_points.positive?
max_lat = Tracepoint.where(:gpx_id => id).maximum(:latitude)
min_lat = Tracepoint.where(:gpx_id => id).minimum(:latitude)
trace.reload
assert_equal 1, Tracepoint.where(:gpx_id => trace.id).count
trace.reload
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