fix n+1
This commit is contained in:
@@ -9,9 +9,17 @@ module Templates
|
|||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def call(template, schema_documents = template.schema_documents, preview_image_attachments = [])
|
def call(template, schema_documents = template.schema_documents.preload(:blob), preview_image_attachments = nil)
|
||||||
json = template.as_json(SERIALIZE_PARAMS)
|
json = template.as_json(SERIALIZE_PARAMS)
|
||||||
|
|
||||||
|
preview_image_attachments ||=
|
||||||
|
ActiveStorage::Attachment.joins(:blob)
|
||||||
|
.where(blob: { filename: '0.jpg' })
|
||||||
|
.where(record_id: schema_documents.map(&:id),
|
||||||
|
record_type: 'ActiveStorage::Attachment',
|
||||||
|
name: :preview_images)
|
||||||
|
.preload(:blob)
|
||||||
|
|
||||||
json[:documents] = template.schema.map do |item|
|
json[:documents] = template.schema.map do |item|
|
||||||
attachment = schema_documents.find { |e| e.uuid == item['attachment_uuid'] }
|
attachment = schema_documents.find { |e| e.uuid == item['attachment_uuid'] }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user