Optimize clear_ai_cache to batch unlock attributes

Replace N individual update calls with single update_column for better performance.
This commit is contained in:
eureka928
2026-01-26 09:50:05 +01:00
parent b82757f58e
commit ed8185cf2b

View File

@@ -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