mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 03:24:09 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user