Check OwnTracks/Overland point for duplicates before saving it

This commit is contained in:
Eugene Burmakin 2024-05-29 23:12:00 +02:00
parent 8559449355
commit a90d6f1f39
5 changed files with 38 additions and 3 deletions

View file

@ -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

View file

@ -7,7 +7,20 @@ class Overland::BatchCreatingJob < ApplicationJob
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

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Overland::BatchCreatingJob, type: :job do
@ -18,5 +20,13 @@ RSpec.describe Overland::BatchCreatingJob, type: :job do
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

View file

@ -20,9 +20,9 @@ RSpec.describe Owntracks::PointCreatingJob, type: :job do
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

View file

@ -180,7 +180,7 @@ paths:
lat: 52.502397
lon: 13.356718
tid: Swagger
tst: 1717016815
tst: 1717017097
servers:
- url: http://{defaultHost}
variables: