diff --git a/CHANGELOG.md b/CHANGELOG.md index bc393862..cfd994dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.4.2] — 2024-05-29 + +### Changed + +- Routes are now being split into separate one. If distance between two consecutive points is more than 500 meters, the route is split into two separate routes. This improves visibility of the routes on the map. +- Background jobs concurrency is increased from 5 to 10 to speed up the processing of the points. + +### Fixed + +- Point data, accepted from OwnTracks and Overland, is now being checked for duplicates. If a point with the same timestamp and coordinates already exists in the database, it will not be saved. + +--- ## [0.4.1] — 2024-05-25 ### Added diff --git a/app/jobs/overland/batch_creating_job.rb b/app/jobs/overland/batch_creating_job.rb index a3d6da1d..6c6ca3ea 100644 --- a/app/jobs/overland/batch_creating_job.rb +++ b/app/jobs/overland/batch_creating_job.rb @@ -7,7 +7,20 @@ def perform(params, user_id) data = Overland::Params.new(params).call data.each do |location| + next if point_exists?(location, user_id) + Point.create!(location.merge(user_id:)) end end + + private + + def point_exists?(params, user_id) + Point.exists?( + latitude: params[:latitude], + longitude: params[:longitude], + timestamp: params[:timestamp], + user_id: + ) + end end diff --git a/spec/jobs/overland/batch_creating_job_spec.rb b/spec/jobs/overland/batch_creating_job_spec.rb index d1d842c8..75446df1 100644 --- a/spec/jobs/overland/batch_creating_job_spec.rb +++ b/spec/jobs/overland/batch_creating_job_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Overland::BatchCreatingJob, type: :job do @@ -18,5 +20,13 @@ expect(Point.last.user_id).to eq(user.id) end + + context 'when point already exists' do + it 'does not create a point' do + perform + + expect { perform }.not_to(change { Point.count }) + end + end end end diff --git a/spec/jobs/owntracks/point_creating_job_spec.rb b/spec/jobs/owntracks/point_creating_job_spec.rb index a9cb2ad3..b104da1a 100644 --- a/spec/jobs/owntracks/point_creating_job_spec.rb +++ b/spec/jobs/owntracks/point_creating_job_spec.rb @@ -20,9 +20,9 @@ end context 'when point already exists' do - before { create(:point, latitude: 1.0, longitude: 1.0, timestamp: Time.now.to_i, user:) } - it 'does not create a point' do + perform + expect { perform }.not_to(change { Point.count }) end end diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml index 786787ba..474bc772 100644 --- a/swagger/v1/swagger.yaml +++ b/swagger/v1/swagger.yaml @@ -180,7 +180,7 @@ paths: lat: 52.502397 lon: 13.356718 tid: Swagger - tst: 1717016815 + tst: 1717017097 servers: - url: http://{defaultHost} variables: