We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 38693e7 commit 80484eaCopy full SHA for 80484ea
app/models/concerns/enrichable.rb
@@ -31,11 +31,13 @@ def clear_ai_cache
31
# Find all AI enrichments for this model
32
ai_enrichments = DataEnrichment.where(enrichable_type: name, source: "ai")
33
34
- # Group by enrichable_id to batch update
+ # Get all enrichable_ids and load records in one query
35
+ enrichable_ids = ai_enrichments.distinct.pluck(:enrichable_id)
36
+ records = where(id: enrichable_ids).index_by(&:id)
37
enrichments_by_id = ai_enrichments.group_by(&:enrichable_id)
38
39
enrichments_by_id.each do |enrichable_id, enrichments|
- record = find_by(id: enrichable_id)
40
+ record = records[enrichable_id]
41
next unless record
42
43
# Unlock all AI-locked attributes
0 commit comments