Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Optimize clear_ai_cache to batch unlock attributes

eureka928ed8185cf2bbb
diff --git a/app/models/concerns/enrichable.rb b/app/models/concerns/enrichable.rb
index d9e0fc38ba..04c557dc65 100644
--- a/app/models/concerns/enrichable.rb
+++ b/app/models/concerns/enrichable.rb
@@ -153,9 +153,10 @@ module Enrichable
# Find attributes that were locked by AI enrichment
ai_enriched_attrs = data_enrichments.where(source: "ai").pluck(:attribute_name).uniq
- # Remove locks for AI-enriched attributes
- ai_enriched_attrs.each do |attr|
- unlock_attr!(attr) if locked?(attr)
+ # Batch unlock all AI-enriched attributes in a single update
+ if ai_enriched_attrs.any?
+ new_locked_attrs = locked_attributes.except(*ai_enriched_attrs)
+ update_column(:locked_attributes, new_locked_attrs) if new_locked_attrs != locked_attributes
end
# Delete AI enrichment records