diff --git a/CHANGELOG.md b/CHANGELOG.md index e35e26e5..5394d6ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/services/imports/create.rb b/app/services/imports/create.rb index 58079188..d920f374 100644 --- a/app/services/imports/create.rb +++ b/app/services/imports/create.rb @@ -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