Refactor clear_ai_cache to use family_scope pattern

- Move family-scoped queries to models via family_scope class method
- Remove hardcoded model names from Enrichable concern
- Replace inline rescue with proper respond_to? check
- Add count tracking for better logging
This commit is contained in:
eureka928
2026-01-26 10:17:28 +01:00
parent 029d09685e
commit 23e9749ed1
4 changed files with 25 additions and 20 deletions

View File

@@ -66,6 +66,11 @@ class Entry < ApplicationRecord
pending.where("entries.date < ?", days.days.ago.to_date)
}
# Family-scoped query for Enrichable#clear_ai_cache
def self.family_scope(family)
joins(:account).where(accounts: { family_id: family.id })
end
# Auto-exclude stale pending transactions for an account
# Called during sync to clean up pending transactions that never posted
# @param account [Account] The account to clean up