Speed up scheduling of visits suggestions job after import

This commit is contained in:
Eugene Burmakin 2025-09-23 21:03:49 +02:00
parent a84fde553e
commit 4627ed7a6f
2 changed files with 5 additions and 5 deletions

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Stats will now properly reflect countries and cities visited after importing new points.
- `GET /api/v1/points will now return correct latitude and longitude values. #1502
- Deleting an import will now trigger stats recalculation for affected months. #1789
- Importing process should now schedule visits suggestions job a lot faster.
## Changed

View file

@ -78,12 +78,11 @@ class Imports::Create
def schedule_visit_suggesting(user_id, import)
return unless user.safe_settings.visits_suggestions_enabled?
points = import.points.order(:timestamp)
min_max = import.points.pluck('MIN(timestamp), MAX(timestamp)').first
return if min_max.compact.empty?
return if points.none?
start_at = Time.zone.at(points.first.timestamp)
end_at = Time.zone.at(points.last.timestamp)
start_at = Time.zone.at(min_max[0])
end_at = Time.zone.at(min_max[1])
VisitSuggestingJob.perform_later(user_id:, start_at:, end_at:)
end