Skip to content

Commit

Permalink
Check OwnTracks/Overland point for duplicates before saving it
Browse files Browse the repository at this point in the history
  • Loading branch information
Freika committed May 29, 2024
1 parent 8559449 commit a90d6f1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/jobs/overland/batch_creating_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions spec/jobs/overland/batch_creating_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Overland::BatchCreatingJob, type: :job do
Expand All @@ -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
4 changes: 2 additions & 2 deletions spec/jobs/owntracks/point_creating_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion swagger/v1/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ paths:
lat: 52.502397
lon: 13.356718
tid: Swagger
tst: 1717016815
tst: 1717017097
servers:
- url: http://{defaultHost}
variables:
Expand Down

0 comments on commit a90d6f1

Please sign in to comment.