Limit stats update after import to the timespan of the imported data

This commit is contained in:
Eugene Burmakin 2024-10-24 17:20:37 +02:00
parent 19b12462b8
commit a4aaa0294f
4 changed files with 20 additions and 4 deletions

View file

@ -5,6 +5,16 @@ 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.15.8 - 2024-10-24
### Fixed
- Stats distance calculation now correctly calculates the daily distances.
### Changed
- Refactored the stats calculation process to make it more efficient.
# 0.15.8 - 2024-10-22
### Added

View file

@ -35,7 +35,10 @@ class Imports::Create
end
def schedule_stats_creating(user_id)
Stats::CalculatingJob.perform_later(user_id)
start_at = import.points.order(:timestamp).first.recorded_at
end_at = import.points.order(:timestamp).last.recorded_at
Stats::CalculatingJob.perform_later(user_id, start_at:, end_at:)
end
def schedule_visit_suggesting(user_id, import)

View file

@ -3,7 +3,7 @@
FactoryBot.define do
factory :import do
user
name { 'APRIL_2013.json' }
name { 'MARCH_2024.json' }
source { Import.sources[:owntracks] }
raw_data { OwnTracks::RecParser.new(File.read('spec/fixtures/files/owntracks/2024-03.rec')).call }
end

View file

@ -7,14 +7,17 @@ RSpec.describe ImportJob, type: :job do
subject(:perform) { described_class.new.perform(user.id, import.id) }
let(:user) { create(:user) }
let(:import) { create(:import, user:, name: 'owntracks_export.json') }
let!(:import) { create(:import, user:, name: 'owntracks_export.json') }
let!(:import_points) { create_list(:point, 9, import: import) }
let(:start_at) { Time.zone.at(1_709_283_789) } # Timestamp of the first point in the "2024-03.rec" fixture file
let(:end_at) { import.points.reload.order(:timestamp).last.recorded_at }
it 'creates points' do
expect { perform }.to change { Point.count }.by(9)
end
it 'calls Stats::CalculatingJob' do
expect(Stats::CalculatingJob).to receive(:perform_later).with(user.id)
expect(Stats::CalculatingJob).to receive(:perform_later).with(user.id, start_at:, end_at:)
perform
end