From 86ad0a4e8d7c03664a6de999661cb84f0838ac46 Mon Sep 17 00:00:00 2001 From: bucketfishy Date: Wed, 24 Jun 2026 11:43:30 -0400 Subject: [PATCH] fix(streak backfill): catch pre-migration streak syncing --- app/models/streak_activity.rb | 7 ++++--- app/models/user/hackatime_project.rb | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/streak_activity.rb b/app/models/streak_activity.rb index dc076673a..536fa736f 100644 --- a/app/models/streak_activity.rb +++ b/app/models/streak_activity.rb @@ -47,8 +47,9 @@ def sync_for_user!(user) project_keys = linked_projects.pluck(:name) today = streak_date_for(Time.current, user.timezone) - start_date = if user.streak_synced_at - streak_date_for(user.streak_synced_at, user.timezone) + last_synced = user.try(:streak_synced_at) + start_date = if last_synced + streak_date_for(last_synced, user.timezone) else Date.parse(HackatimeService::START_DATE) end @@ -71,7 +72,7 @@ def sync_for_user!(user) record.update!(coded_seconds: seconds) end - user.update_column(:streak_synced_at, Time.current) + user.update_column(:streak_synced_at, Time.current) if user.has_attribute?(:streak_synced_at) end def streak_date_for(time, timezone) diff --git a/app/models/user/hackatime_project.rb b/app/models/user/hackatime_project.rb index 9737897d4..1e2198dd4 100644 --- a/app/models/user/hackatime_project.rb +++ b/app/models/user/hackatime_project.rb @@ -39,7 +39,7 @@ class User::HackatimeProject < ApplicationRecord private def enqueue_streak_resync - user.update_column(:streak_synced_at, nil) + user.update_column(:streak_synced_at, nil) if user.has_attribute?(:streak_synced_at) StreakSyncJob.perform_later(user_id) end