From 1ce66a14946d60a676a4f467cb77893b07baf696 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 5 Mar 2025 22:36:56 +0100 Subject: [PATCH] Prevent places duplicates --- CHANGELOG.md | 4 ++++ app/jobs/visit_suggesting_job.rb | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fbd7518..e8c4384f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ 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/). +TODO: + +- Selecting a visit should put it above other visits on the map to make it easier to edit it. If many visits are on the same place, we should be able to click on them + # 0.24.2 - 2025-02-24 ## Added diff --git a/app/jobs/visit_suggesting_job.rb b/app/jobs/visit_suggesting_job.rb index e217dd4d..f8346d25 100644 --- a/app/jobs/visit_suggesting_job.rb +++ b/app/jobs/visit_suggesting_job.rb @@ -6,12 +6,20 @@ class VisitSuggestingJob < ApplicationJob def perform(user_ids: [], start_at: 1.day.ago, end_at: Time.current) users = user_ids.any? ? User.where(id: user_ids) : User.all + start_at = start_at.to_datetime + end_at = end_at.to_datetime users.find_each do |user| next unless user.active? next if user.tracked_points.empty? - Visits::Suggest.new(user, start_at:, end_at:).call + # Split the time range into 24-hour chunks + # This prevents from places duplicates + time_chunks = (start_at..end_at).step(1.day).to_a + + time_chunks.each do |time_chunk| + Visits::Suggest.new(user, start_at: time_chunk, end_at: time_chunk + 1.day).call + end end end end