From 43c7cc03a52d1aedb3e59d13a6afff3554de41a5 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 23 Sep 2022 04:46:39 +0000 Subject: [PATCH] Retrieve attachments with a single query when rendering a journal (#37687). Patch by Go MAEDA. git-svn-id: https://svn.redmine.org/redmine/trunk@21831 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/journal.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 919a07dd2..a4efcdbee 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -142,7 +142,8 @@ class Journal < ActiveRecord::Base end def attachments - details.select{ |d| d.property == 'attachment' }.map{ |d| Attachment.find_by(:id => d.prop_key) }.compact + ids = details.select {|d| d.property == 'attachment' && d.value.present?}.map(&:prop_key) + Attachment.where(id: ids).to_a end # Returns a string of css classes -- 2.39.5