Merge pull request #629 from Freika/chore/various-fixes-1

Various fixes #1
This commit is contained in:
Evgenii Burmakin 2025-01-07 15:19:21 +01:00 committed by GitHub
commit 2aa168ce5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 83 additions and 28 deletions

View file

@ -1 +1 @@
0.21.5
0.21.6

View file

@ -5,6 +5,19 @@ 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.21.6 - 2025-01-07
### Changed
- Disabled visit suggesting job after import.
- Improved performance of the `User#years_tracked` method.
### Fixed
- Inconsistent password for the `dawarich_db` service in `docker-compose_mounted_volumes.yml`. #605
- Points are now being rendered with higher z-index than polylines. #577
- Run cache cleaning and preheating jobs only on server start. #594
# 0.21.5 - 2025-01-07
You may now use Geoapify API for reverse geocoding. To obtain an API key, sign up at https://myprojects.geoapify.com/ and create a new project. Make sure you have read and understood the [pricing policy](https://www.geoapify.com/pricing) and [Terms and Conditions](https://www.geoapify.com/terms-and-conditions/).

File diff suppressed because one or more lines are too long

View file

@ -43,8 +43,9 @@ export default class extends Controller {
const polyline = L.polyline(points, {
color: 'blue',
opacity: 0.8,
weight: 3,
opacity: 0.8
zIndexOffset: 400
}).addTo(this.map)
this.map.fitBounds(polyline.getBounds(), {

View file

@ -138,7 +138,14 @@ export default class extends Controller {
addMarkers() {
this.coordinates.forEach(coord => {
const marker = L.circleMarker([coord[0], coord[1]], {radius: 4})
const marker = L.circleMarker(
[coord[0], coord[1]],
{
radius: 4,
color: coord[5] < 0 ? "orange" : "blue",
zIndexOffset: 1000
}
)
const popupContent = createPopupContent(coord, this.timezone, this.distanceUnit)
marker.bindPopup(popupContent)
@ -152,8 +159,9 @@ export default class extends Controller {
const points = this.coordinates.map(coord => [coord[0], coord[1]])
const polyline = L.polyline(points, {
color: 'blue',
opacity: 0.8,
weight: 3,
opacity: 0.8
zIndexOffset: 400
})
// Add to polylines layer instead of directly to map
this.polylinesLayer.addTo(this.map)

View file

@ -27,7 +27,15 @@ export default class extends Controller {
addMarkers() {
this.coordinates.forEach((coordinate) => {
L.circleMarker([coordinate[0], coordinate[1]], { radius: 4 }).addTo(this.map);
L.circleMarker(
[coordinate[0], coordinate[1]],
{
radius: 4,
color: coordinate[5] < 0 ? "orange" : "blue",
zIndexOffset: 1000
}
).addTo(this.map);
});
}
}

View file

@ -12,7 +12,8 @@ export function createMarkersArray(markersData, userSettings) {
return L.circleMarker([lat, lon], {
radius: 4,
color: markerColor,
zIndexOffset: 1000
zIndexOffset: 1000,
pane: 'markerPane'
}).bindPopup(popupContent, { autoClose: false });
});
}
@ -47,6 +48,9 @@ export function createSimplifiedMarkers(markersData) {
const [lat, lon] = marker;
const popupContent = createPopupContent(marker);
let markerColor = marker[5] < 0 ? "orange" : "blue";
return L.circleMarker([lat, lon], { radius: 4, color: markerColor }).bindPopup(popupContent);
return L.circleMarker(
[lat, lon],
{ radius: 4, color: markerColor, zIndexOffset: 1000 }
).bindPopup(popupContent);
});
}

View file

@ -126,7 +126,8 @@ export function createPolylinesLayer(markers, map, timezone, routeOpacity, userS
color: "blue",
opacity: 0.6,
weight: 3,
zIndexOffset: 400
zIndexOffset: 400,
pane: 'overlayPane'
});
addHighlightOnHover(polyline, map, polylineCoordinates, userSettings, distanceUnit);

View file

@ -5,7 +5,11 @@ class Cache::PreheatingJob < ApplicationJob
def perform
User.find_each do |user|
Rails.cache.write("dawarich/user_#{user.id}_years_tracked", user.years_tracked, expires_in: 1.day)
Rails.cache.write(
"dawarich/user_#{user.id}_years_tracked",
user.years_tracked,
expires_in: 1.day
)
end
end
end

View file

@ -66,15 +66,23 @@ class User < ApplicationRecord
def years_tracked
Rails.cache.fetch("dawarich/user_#{id}_years_tracked", expires_in: 1.day) do
tracked_points
.pluck(:timestamp)
.map { |ts| Time.zone.at(ts) }
.group_by(&:year)
.transform_values do |dates|
dates.map { |date| date.strftime('%b') }.uniq.sort
end
# Use select_all for better performance with large datasets
sql = <<-SQL
SELECT DISTINCT
EXTRACT(YEAR FROM TO_TIMESTAMP(timestamp)) AS year,
TO_CHAR(TO_TIMESTAMP(timestamp), 'Mon') AS month
FROM points
WHERE user_id = #{id}
ORDER BY year DESC, month ASC
SQL
result = ActiveRecord::Base.connection.select_all(sql)
result
.map { |r| [r['year'].to_i, r['month']] }
.group_by { |year, _| year }
.transform_values { |year_data| year_data.map { |_, month| month } }
.map { |year, months| { year: year, months: months } }
.sort_by { |entry| -entry[:year] } # Sort in descending order
end
end

View file

@ -4,6 +4,7 @@ class Cache::Clean
class << self
def call
Rails.logger.info('Cleaning cache...')
delete_control_flag
delete_version_cache
delete_years_tracked_cache
Rails.logger.info('Cache cleaned')
@ -11,6 +12,10 @@ class Cache::Clean
private
def delete_control_flag
Rails.cache.delete('cache_jobs_scheduled')
end
def delete_version_cache
Rails.cache.delete(CheckAppVersion::VERSION_CACHE_KEY)
end

View file

@ -14,7 +14,7 @@ class Imports::Create
create_import_finished_notification(import, user)
schedule_stats_creating(user.id)
schedule_visit_suggesting(user.id, import)
# schedule_visit_suggesting(user.id, import) # Disabled until places & visits are reworked
rescue StandardError => e
create_import_failed_notification(import, user, e)
end

View file

@ -6,8 +6,11 @@ require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
# Clear the cache
Cache::CleaningJob.perform_later
# Use an atomic operation to ensure one-time execution
if defined?(Rails::Server) && Rails.cache.write('cache_jobs_scheduled', true, unless_exist: true)
# Clear the cache
Cache::CleaningJob.perform_later
# Preheat the cache
Cache::PreheatingJob.perform_later
# Preheat the cache
Cache::PreheatingJob.perform_later
end

View file

@ -152,7 +152,7 @@ services:
- dawarich
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: eJH3YZsVc2s6byhFwpEny
POSTGRES_PASSWORD: password
POSTGRES_DATABASE: dawarich
volumes:
- ./db:/var/lib/postgresql/data

View file

@ -50,7 +50,7 @@ RSpec.describe Imports::Create do
end
end
it 'schedules visit suggesting' do
xit 'schedules visit suggesting' do
Sidekiq::Testing.inline! do
expect { service.call }.to have_enqueued_job(VisitSuggestingJob)
end
@ -59,7 +59,7 @@ RSpec.describe Imports::Create do
context 'when import fails' do
before do
allow(OwnTracks::ExportParser).to receive(:new).with(import, user.id).and_return(double(call: false))
allow(OwnTracks::ExportParser).to receive(:new).with(import, user.id).and_raise(StandardError)
end
it 'creates a failed notification' do