Compare commits

...

8 commits

Author SHA1 Message Date
Evgenii Burmakin
ed350971ee
Merge pull request #1540 from Freika/fix/place-osm-id-index
Add index on places geodata osm id
2025-07-21 23:30:44 +02:00
Eugene Burmakin
c18b09181e Add index on places geodata osm id 2025-07-21 22:45:57 +02:00
Evgenii Burmakin
7c1c42dfc1
Merge pull request #1539 from Freika/fix/cache-point-limit-result
Add cache to points limit exceeded check
2025-07-21 22:35:22 +02:00
Eugene Burmakin
7afc399724 Add cache to points limit exceeded check 2025-07-21 22:27:20 +02:00
Eugene Burmakin
2206622726 Release 0.30.0 2025-07-21 20:35:43 +02:00
Eugene Burmakin
9bcd522e25 Update specs 2025-07-21 20:22:18 +02:00
Eugene Burmakin
6a6c3c938f Fix distance calculation 2025-07-21 19:00:28 +02:00
Eugene Burmakin
59a4d760bf Fix owntracks points creation 2025-07-21 18:59:13 +02:00
13 changed files with 73 additions and 12 deletions

View file

@ -1 +1 @@
0.29.2 0.30.1

View file

@ -4,10 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
# [0.30.1] - 2025-07-21
# [0.29.2] - 2025-07-12 ## Fixed
⚠️ If you were using RC, please run the following commands in the console, otherwise read on. ⚠️ - Points limit exceeded check is now cached.
- Reverse geocoding for places is now significantly faster.
# [0.30.0] - 2025-07-21
⚠️ If you were using 0.29.2 RC, please run the following commands in the console, otherwise read on. ⚠️
```ruby ```ruby
# This will delete all tracks 👇 # This will delete all tracks 👇
@ -73,6 +80,8 @@ end
- Swagger documentation is now valid again. - Swagger documentation is now valid again.
- Invalid owntracks points are now ignored. - Invalid owntracks points are now ignored.
- An older Owntrack's .rec format is now also supported.
- Course and course accuracy are now rounded to 8 decimal places to fix the issue with points creation.
# [0.29.1] - 2025-07-02 # [0.29.1] - 2025-07-02

View file

@ -36,17 +36,17 @@ class MapController < ApplicationController
end end
def calculate_distance def calculate_distance
total_distance_meters = 0 total_distance = 0
@coordinates.each_cons(2) do @coordinates.each_cons(2) do
distance_km = Geocoder::Calculations.distance_between( distance_km = Geocoder::Calculations.distance_between(
[_1[0], _1[1]], [_2[0], _2[1]], units: :km [_1[0], _1[1]], [_2[0], _2[1]], units: :km
) )
total_distance_meters += distance_km total_distance += distance_km
end end
total_distance_meters.round total_distance.round
end end
def parsed_start_at def parsed_start_at

View file

@ -9,8 +9,12 @@ class OwnTracks::RecParser
def call def call
file.split("\n").map do |line| file.split("\n").map do |line|
# Try tab-separated first, then fall back to whitespace-separated
parts = line.split("\t") parts = line.split("\t")
# If tab splitting didn't work (only 1 part), try whitespace splitting
parts = line.split(/\s+/) if parts.size == 1
Oj.load(parts[2]) if parts.size > 2 && parts[1].strip == '*' Oj.load(parts[2]) if parts.size > 2 && parts[1].strip == '*'
end.compact end.compact
end end

View file

@ -7,13 +7,18 @@ class PointsLimitExceeded
def call def call
return false if DawarichSettings.self_hosted? return false if DawarichSettings.self_hosted?
return true if @user.tracked_points.count >= points_limit
false Rails.cache.fetch(cache_key, expires_in: 1.day) do
@user.tracked_points.count >= points_limit
end
end end
private private
def cache_key
"points_limit_exceeded/#{@user.id}"
end
def points_limit def points_limit
DawarichSettings::BASIC_PAID_PLAN_LIMIT DawarichSettings::BASIC_PAID_PLAN_LIMIT
end end

View file

@ -0,0 +1,10 @@
class AddIndexOnPlacesGeodataOsmId < ActiveRecord::Migration[8.0]
disable_ddl_transaction!
def change
add_index :places, "(geodata->'properties'->>'osm_id')",
using: :btree,
name: 'index_places_on_geodata_osm_id',
algorithm: :concurrently
end
end

6
db/schema.rb generated
View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_07_03_193657) do ActiveRecord::Schema[8.0].define(version: 2025_07_21_204404) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql" enable_extension "pg_catalog.plpgsql"
enable_extension "postgis" enable_extension "postgis"
@ -77,6 +77,9 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_03_193657) do
t.index ["name"], name: "index_countries_on_name" t.index ["name"], name: "index_countries_on_name"
end end
create_table "data_migrations", primary_key: "version", id: :string, force: :cascade do |t|
end
create_table "exports", force: :cascade do |t| create_table "exports", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "url" t.string "url"
@ -143,6 +146,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_03_193657) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.geography "lonlat", limit: {srid: 4326, type: "st_point", geographic: true} t.geography "lonlat", limit: {srid: 4326, type: "st_point", geographic: true}
t.index "(((geodata -> 'properties'::text) ->> 'osm_id'::text))", name: "index_places_on_geodata_osm_id"
t.index ["lonlat"], name: "index_places_on_lonlat", using: :gist t.index ["lonlat"], name: "index_places_on_lonlat", using: :gist
end end

View file

@ -13,7 +13,7 @@ FactoryBot.define do
settings do settings do
{ {
'route_opacity' => '50', 'route_opacity' => 60,
'meters_between_routes' => '500', 'meters_between_routes' => '500',
'minutes_between_routes' => '30', 'minutes_between_routes' => '30',
'fog_of_war_meters' => '100', 'fog_of_war_meters' => '100',

View file

@ -0,0 +1,10 @@
2023-02-20T18:46:22Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918783,"lat":22.0687934,"lon":24.7941786,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918782,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:25Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":13,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918785,"lat":22.0687967,"lon":24.7941813,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918785,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:25Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":13,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918790,"lat":22.0687967,"lon":24.7941813,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918785,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:35Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918795,"lat":22.0687906,"lon":24.794195,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918795,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:40Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918800,"lat":22.0687967,"lon":24.7941859,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918800,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:45Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918805,"lat":22.0687946,"lon":24.7941883,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918805,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:50Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918810,"lat":22.0687912,"lon":24.7941837,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918810,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:55Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918815,"lat":22.0687927,"lon":24.794186,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918815,"vac":0,"vel":0,"_http":true}
2023-02-20T18:46:55Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918815,"lat":22.0687937,"lon":24.794186,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918815,"vac":0,"vel":0,"_http":true}
2023-02-20T18:47:00Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918820,"lat":22.0687937,"lon":24.794186,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918820,"vac":0,"vel":0,"_http":true}

View file

@ -92,7 +92,7 @@ RSpec.describe TrackSerializer do
let(:track) { create(:track, user: user, original_path: 'LINESTRING(0 0, 1 1, 2 2)') } let(:track) { create(:track, user: user, original_path: 'LINESTRING(0 0, 1 1, 2 2)') }
it 'converts geometry to WKT string format' do it 'converts geometry to WKT string format' do
expect(serialized_track[:original_path]).to eq('LINESTRING (0 0, 1 1, 2 2)') expect(serialized_track[:original_path]).to match(/LINESTRING \(0(\.0)? 0(\.0)?, 1(\.0)? 1(\.0)?, 2(\.0)? 2(\.0)?\)/)
expect(serialized_track[:original_path]).to be_a(String) expect(serialized_track[:original_path]).to be_a(String)
end end
end end

View file

@ -78,5 +78,19 @@ RSpec.describe OwnTracks::Importer do
expect(Point.first.velocity).to eq('1.4') expect(Point.first.velocity).to eq('1.4')
end end
end end
context 'when file is old' do
let(:file_path) { Rails.root.join('spec/fixtures/files/owntracks/2023-02_old.rec') }
it 'creates points' do
expect { parser }.to change { Point.count }.by(9)
end
it 'correctly writes attributes' do
parser
point = Point.first
end
end
end end
end end

View file

@ -28,6 +28,11 @@ RSpec.describe PointsLimitExceeded do
end end
it { is_expected.to be true } it { is_expected.to be true }
it 'caches the result' do
expect(user.tracked_points).to receive(:count).once
2.times { described_class.new(user).call }
end
end end
context 'when user points count exceeds the limit' do context 'when user points count exceeds the limit' do

View file

@ -447,7 +447,7 @@ RSpec.describe 'Map Interaction', type: :system do
# Find and update route opacity # Find and update route opacity
within('.leaflet-settings-panel') do within('.leaflet-settings-panel') do
opacity_input = find('#route-opacity') opacity_input = find('#route-opacity')
expect(opacity_input.value).to eq('50') # Default value expect(opacity_input.value).to eq('60') # Default value
# Change opacity to 80% # Change opacity to 80%
opacity_input.fill_in(with: '80') opacity_input.fill_in(with: '80')