]> source.dussan.org Git - redmine.git/commitdiff
Retrieve attachments with a single query when rendering a journal (#37687).
authorGo MAEDA <maeda@farend.jp>
Fri, 23 Sep 2022 04:46:39 +0000 (04:46 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 23 Sep 2022 04:46:39 +0000 (04:46 +0000)
Patch by Go MAEDA.

git-svn-id: https://svn.redmine.org/redmine/trunk@21831 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/journal.rb

index 919a07dd2e9b2d629f5a5a0775472b926e84e91f..a4efcdbeecb3491d3ffd027a84b70cfb1328115e 100644 (file)
@@ -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