mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Start reverse geocoding after import is finished
This commit is contained in:
parent
0dfdeac5c5
commit
0276882db1
10 changed files with 47 additions and 17 deletions
|
|
@ -1 +1 @@
|
||||||
0.21.1
|
0.21.2
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,12 @@ 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.21.2 - 2024-12-25
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Imported points will now be reverse geocoded only after import is finished.
|
||||||
|
|
||||||
# 0.21.1 - 2024-12-24
|
# 0.21.1 - 2024-12-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -10,31 +10,20 @@ export default class extends Controller {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log("Imports controller connected", {
|
|
||||||
// hasIndexTarget: this.hasIndexTarget,
|
|
||||||
// element: this.element,
|
|
||||||
// userId: this.element.dataset.userId
|
|
||||||
// });
|
|
||||||
this.setupSubscription();
|
this.setupSubscription();
|
||||||
}
|
}
|
||||||
|
|
||||||
setupSubscription() {
|
setupSubscription() {
|
||||||
const userId = this.element.dataset.userId;
|
const userId = this.element.dataset.userId;
|
||||||
// console.log("Setting up subscription with userId:", userId);
|
|
||||||
|
|
||||||
this.channel = consumer.subscriptions.create(
|
this.channel = consumer.subscriptions.create(
|
||||||
{ channel: "ImportsChannel" },
|
{ channel: "ImportsChannel" },
|
||||||
{
|
{
|
||||||
connected: () => {
|
connected: () => {
|
||||||
// console.log("Successfully connected to ImportsChannel");
|
|
||||||
// Test that we can receive messages
|
|
||||||
// console.log("Subscription object:", this.channel);
|
|
||||||
},
|
},
|
||||||
disconnected: () => {
|
disconnected: () => {
|
||||||
// console.log("Disconnected from ImportsChannel");
|
|
||||||
},
|
},
|
||||||
received: (data) => {
|
received: (data) => {
|
||||||
// console.log("Received data:", data);
|
|
||||||
const row = this.element.querySelector(`tr[data-import-id="${data.import.id}"]`);
|
const row = this.element.querySelector(`tr[data-import-id="${data.import.id}"]`);
|
||||||
|
|
||||||
if (row) {
|
if (row) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Import < ApplicationRecord
|
class Import < ApplicationRecord
|
||||||
# self.ignored_columns = %w[raw_data]
|
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_many :points, dependent: :destroy
|
has_many :points, dependent: :destroy
|
||||||
|
|
||||||
|
|
@ -17,6 +15,10 @@ class Import < ApplicationRecord
|
||||||
Imports::Create.new(user, self).call
|
Imports::Create.new(user, self).call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reverse_geocoded_points_count
|
||||||
|
points.reverse_geocoded.count
|
||||||
|
end
|
||||||
|
|
||||||
def years_and_months_tracked
|
def years_and_months_tracked
|
||||||
points.order(:timestamp).pluck(:timestamp).map do |timestamp|
|
points.order(:timestamp).pluck(:timestamp).map do |timestamp|
|
||||||
time = Time.zone.at(timestamp)
|
time = Time.zone.at(timestamp)
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,9 @@ class Point < ApplicationRecord
|
||||||
Time.zone.at(timestamp)
|
Time.zone.at(timestamp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def async_reverse_geocode
|
def async_reverse_geocode(force: false)
|
||||||
return unless REVERSE_GEOCODING_ENABLED
|
return unless REVERSE_GEOCODING_ENABLED
|
||||||
|
return if import_id.present? && !force
|
||||||
|
|
||||||
ReverseGeocodingJob.perform_later(self.class.to_s, id)
|
ReverseGeocodingJob.perform_later(self.class.to_s, id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class Imports::Create
|
||||||
|
|
||||||
schedule_stats_creating(user.id)
|
schedule_stats_creating(user.id)
|
||||||
schedule_visit_suggesting(user.id, import)
|
schedule_visit_suggesting(user.id, import)
|
||||||
|
schedule_reverse_geocoding(user.id)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
create_import_failed_notification(import, user, e)
|
create_import_failed_notification(import, user, e)
|
||||||
end
|
end
|
||||||
|
|
@ -47,6 +48,10 @@ class Imports::Create
|
||||||
VisitSuggestingJob.perform_later(user_ids: [user_id], start_at:, end_at:)
|
VisitSuggestingJob.perform_later(user_ids: [user_id], start_at:, end_at:)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def schedule_reverse_geocoding(user_id)
|
||||||
|
EnqueueBackgroundJob.perform_later('continue_reverse_geocoding', user_id)
|
||||||
|
end
|
||||||
|
|
||||||
def create_import_finished_notification(import, user)
|
def create_import_finished_notification(import, user)
|
||||||
Notifications::Create.new(
|
Notifications::Create.new(
|
||||||
user:,
|
user:,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ class Jobs::Create
|
||||||
raise InvalidJobName, 'Invalid job name'
|
raise InvalidJobName, 'Invalid job name'
|
||||||
end
|
end
|
||||||
|
|
||||||
points.find_each(batch_size: 1_000, &:async_reverse_geocode)
|
points.find_each(batch_size: 1_000) do |point|
|
||||||
|
point.async_reverse_geocode(force: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Imported points</th>
|
<th>Imported points</th>
|
||||||
|
<th>Reverse geocoded points</th>
|
||||||
<th>Created at</th>
|
<th>Created at</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -50,7 +51,9 @@
|
||||||
data-user-id="<%= current_user.id %>"
|
data-user-id="<%= current_user.id %>"
|
||||||
>
|
>
|
||||||
<% @imports.each do |import| %>
|
<% @imports.each do |import| %>
|
||||||
<tr data-import-id="<%= import.id %>" id="import-<%= import.id %>">
|
<tr data-import-id="<%= import.id %>"
|
||||||
|
id="import-<%= import.id %>"
|
||||||
|
data-points-total="<%= import.points_count %>">
|
||||||
<td>
|
<td>
|
||||||
<%= link_to import.name, import, class: 'underline hover:no-underline' %>
|
<%= link_to import.name, import, class: 'underline hover:no-underline' %>
|
||||||
(<%= import.source %>)
|
(<%= import.source %>)
|
||||||
|
|
@ -62,6 +65,9 @@
|
||||||
<td data-points-count>
|
<td data-points-count>
|
||||||
<%= number_with_delimiter import.points_count %>
|
<%= number_with_delimiter import.points_count %>
|
||||||
</td>
|
</td>
|
||||||
|
<td data-reverse-geocoded-points-count>
|
||||||
|
<%= number_with_delimiter import.reverse_geocoded_points_count %>
|
||||||
|
</td>
|
||||||
<td><%= import.created_at.strftime("%d.%m.%Y, %H:%M") %></td>
|
<td><%= import.created_at.strftime("%d.%m.%Y, %H:%M") %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,20 @@ RSpec.describe Point, type: :model do
|
||||||
expect { point.async_reverse_geocode }.to have_enqueued_job(ReverseGeocodingJob)
|
expect { point.async_reverse_geocode }.to have_enqueued_job(ReverseGeocodingJob)
|
||||||
.with('Point', point.id)
|
.with('Point', point.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when point is imported' do
|
||||||
|
let(:point) { build(:point, import_id: 1) }
|
||||||
|
|
||||||
|
it 'does not enqueue ReverseGeocodeJob' do
|
||||||
|
expect { point.async_reverse_geocode }.not_to have_enqueued_job(ReverseGeocodingJob)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when reverse geocoding is forced' do
|
||||||
|
it 'enqueues ReverseGeocodeJob' do
|
||||||
|
expect { point.async_reverse_geocode(force: true) }.to have_enqueued_job(ReverseGeocodingJob)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ RSpec.describe Imports::Create do
|
||||||
expect { service.call }.to have_enqueued_job(VisitSuggestingJob)
|
expect { service.call }.to have_enqueued_job(VisitSuggestingJob)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'schedules reverse geocoding' do
|
||||||
|
expect { service.call }.to \
|
||||||
|
have_enqueued_job(EnqueueBackgroundJob).with('continue_reverse_geocoding', user.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when import fails' do
|
context 'when import fails' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue