Skip to content

Commit 80484ea

Browse files
Update app/models/concerns/enrichable.rb
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: soky srm <[email protected]>
1 parent 38693e7 commit 80484ea

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

app/models/concerns/enrichable.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def clear_ai_cache
3131
# Find all AI enrichments for this model
3232
ai_enrichments = DataEnrichment.where(enrichable_type: name, source: "ai")
3333

34-
# Group by enrichable_id to batch update
34+
# 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)
3537
enrichments_by_id = ai_enrichments.group_by(&:enrichable_id)
3638

3739
enrichments_by_id.each do |enrichable_id, enrichments|
38-
record = find_by(id: enrichable_id)
40+
record = records[enrichable_id]
3941
next unless record
4042

4143
# Unlock all AI-locked attributes

0 commit comments

Comments
 (0)