diff --git a/.rubocop.yml b/.rubocop.yml index c0f0c1fa080..1ac40071443 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -71,6 +71,7 @@ Rails/SkipsModelValidations: Exclude: - 'db/migrate/*.rb' - 'app/controllers/users_controller.rb' + - 'app/models/trace.rb' Style/Documentation: Enabled: false diff --git a/Gemfile b/Gemfile index ac056cd83d8..feff07855f4 100644 --- a/Gemfile +++ b/Gemfile @@ -48,7 +48,6 @@ gem "file_exists" # Load rails plugins gem "actionpack-page_caching", ">= 1.2.0" -gem "activerecord-import" gem "active_record_union" gem "bootstrap", "~> 5.3.2" gem "bootstrap_form", "~> 5.0" diff --git a/Gemfile.lock b/Gemfile.lock index 7642812850d..39b1e6cce73 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,8 +65,6 @@ GEM activemodel (= 7.1.4) activesupport (= 7.1.4) timeout (>= 0.4.0) - activerecord-import (1.8.0) - activerecord (>= 4.2) activestorage (7.1.4) actionpack (= 7.1.4) activejob (= 7.1.4) @@ -617,7 +615,6 @@ DEPENDENCIES aasm actionpack-page_caching (>= 1.2.0) active_record_union - activerecord-import addressable (~> 2.8) annotate argon2 diff --git a/app/models/trace.rb b/app/models/trace.rb index 20723b98d01..6655c56a0c6 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -230,16 +230,17 @@ def import tp.timestamp = point.timestamp tp.gpx_id = id tp.trackid = point.segment + tp.validate! tracepoints << tp end - # Run the before_save and before_create callbacks, and then import them in bulk with activerecord-import + # Run the before_save and before_create callbacks, and then do a bulk insert tracepoints.each do |tp| tp.run_callbacks(:save) { false } tp.run_callbacks(:create) { false } end - Tracepoint.import!(tracepoints) + Tracepoint.insert_all!(tracepoints.map(&:attributes)) end if gpx.actual_points.positive? diff --git a/test/controllers/api/traces_controller_test.rb b/test/controllers/api/traces_controller_test.rb index b26782a3f01..0e26f8adfed 100644 --- a/test/controllers/api/traces_controller_test.rb +++ b/test/controllers/api/traces_controller_test.rb @@ -196,15 +196,31 @@ def test_create create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable") assert_not_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v auth_header = basic_authorization_header user.display_name, "test" - post gpx_create_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" }, :headers => auth_header + + # Create trace and import tracepoints in background job + perform_enqueued_jobs do + post gpx_create_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" }, :headers => auth_header + end assert_response :success + trace = Trace.find(response.body.to_i) assert_equal "a.gpx", trace.name assert_equal "New Trace", trace.description assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag) assert_equal "trackable", trace.visibility - assert_not trace.inserted + assert trace.inserted assert_equal File.new(fixture).read, trace.file.blob.download + + # Validate tracepoints + assert_equal 1, trace.points.size + tp = trace.points.first + assert_equal 10000000, tp.latitude + assert_equal 10000000, tp.longitude + assert_equal 3221331576, tp.tile + assert_equal 0, tp.trackid + assert_in_delta(134.0, tp.altitude) + assert_equal DateTime.parse("2008-10-01T10:10:10.000Z"), tp.timestamp + trace.destroy assert_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v