From 72a0f87a9c3a6a579be9ed9389b97e7e75091f14 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Wed, 25 Jun 2025 15:23:15 -0400 Subject: [PATCH] Fix race condition in sync status monitor (#2412) Move family timestamp update to after_commit callback to ensure database visibility before cache invalidation --- app/models/sync.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/sync.rb b/app/models/sync.rb index 7baf9e63..ea66ebb4 100644 --- a/app/models/sync.rb +++ b/app/models/sync.rb @@ -19,6 +19,8 @@ class Sync < ApplicationRecord scope :incomplete, -> { where("syncs.status IN (?)", %w[pending syncing]) } scope :visible, -> { incomplete.where("syncs.created_at > ?", VISIBLE_FOR.ago) } + after_commit :update_family_sync_timestamp + validate :window_valid # Sync state machine @@ -169,7 +171,6 @@ class Sync < ApplicationRecord def handle_transition log_status_change - family.touch(:latest_sync_activity_at) end def handle_completion_transition @@ -182,6 +183,10 @@ class Sync < ApplicationRecord end end + def update_family_sync_timestamp + family.touch(:latest_sync_activity_at) + end + def family if syncable.is_a?(Family) syncable