From 84143c683fc4968cac289eb4cfa5ff127512cb0c Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Fri, 6 Oct 2023 22:06:54 +0100 Subject: [PATCH] Add some naive filtering to the Toggl scraping job to ignore time entries that have already been tracked --- app/jobs/scrape_toggl_job.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/jobs/scrape_toggl_job.rb b/app/jobs/scrape_toggl_job.rb index 7faf5ff..86e7b68 100644 --- a/app/jobs/scrape_toggl_job.rb +++ b/app/jobs/scrape_toggl_job.rb @@ -31,6 +31,9 @@ class ScrapeTogglJob < ApplicationJob entries_data.each do |entry| entry_title = entry['description'] + # Skip if we've already seen this entry, NOTE: we assume that there is only one inner_entry per time entry + next if TrackedTimeEntry.exists?(associated_toggl_entry_id: entry['time_entries'][0]['id']) + if (lecture = lectures.find_by(title: entry_title)) is_concurrent = entry['time_entries'].any? do |inner_entry| (Time.new(inner_entry['start']) - lecture.start_time).abs < 10.minutes