The personal finance app for everyone (by everyone)
Ruby
fix(sync): resolve N+1 query in child finalization (#2693)
sentry[bot]7b6636d8ea61
diff --git a/app/models/sync.rb b/app/models/sync.rbindex eb0cd4c845..6d34c7ecfd 100644--- a/app/models/sync.rb+++ b/app/models/sync.rb@@ -162,6 +162,10 @@ class Sync < ApplicationRecordSync.transaction dolock!+ # Eagerly load children once so that all_children_finalized? and+ # has_failed_children? can filter in-memory without additional DB queries.+ children.load+# If this is the "parent" and there are still children running, don't finalize.return unless all_children_finalized?@@ -213,11 +217,11 @@ class Sync < ApplicationRecordenddef has_failed_children?- children.failed.any?+ children.any?(&:failed?)enddef all_children_finalized?- children.incomplete.empty?+ children.none? { |child| child.pending? || child.syncing? }enddef perform_post_sync