From 7e0db4c846b420bff7fd05012aff4496df6dfe05 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Tue, 5 Apr 2022 16:49:52 +0200 Subject: [PATCH 1/2] Use eager loading for attachments on queries used in homepage --- .../assemblies/content_blocks/highlighted_assemblies_cell.rb | 1 + .../conferences/organization_prioritized_conferences.rb | 2 +- decidim-core/lib/decidim/has_attachments.rb | 4 ++-- .../content_blocks/highlighted_processes_cell.rb | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/decidim-assemblies/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies_cell.rb b/decidim-assemblies/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies_cell.rb index 8bdc1bf6cb7b5..13b746f733b51 100644 --- a/decidim-assemblies/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies_cell.rb +++ b/decidim-assemblies/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies_cell.rb @@ -22,6 +22,7 @@ def highlighted_assemblies @highlighted_assemblies ||= OrganizationPrioritizedAssemblies .new(current_organization, current_user) .query + .with_attached_hero_image .includes([:organization]) .limit(max_results) end diff --git a/decidim-conferences/app/queries/decidim/conferences/organization_prioritized_conferences.rb b/decidim-conferences/app/queries/decidim/conferences/organization_prioritized_conferences.rb index ab542872098ef..45ce250eb2a12 100644 --- a/decidim-conferences/app/queries/decidim/conferences/organization_prioritized_conferences.rb +++ b/decidim-conferences/app/queries/decidim/conferences/organization_prioritized_conferences.rb @@ -14,7 +14,7 @@ def query Decidim::Query.merge( OrganizationPublishedConferences.new(@organization, @user), PrioritizedConferences.new - ).query + ).query.with_attached_hero_image end end end diff --git a/decidim-core/lib/decidim/has_attachments.rb b/decidim-core/lib/decidim/has_attachments.rb index 4034705839892..0e3f6521dab80 100644 --- a/decidim-core/lib/decidim/has_attachments.rb +++ b/decidim-core/lib/decidim/has_attachments.rb @@ -26,14 +26,14 @@ def photo # # Returns an Array def photos - @photos ||= attachments.order(:weight).select(&:photo?) + @photos ||= attachments.with_attached_file.order(:weight).select(&:photo?) end # All the attachments that are documents for this model. # # Returns an Array def documents - @documents ||= attachments.order(:weight).includes(:attachment_collection).select(&:document?) + @documents ||= attachments.with_attached_file.order(:weight).includes(:attachment_collection).select(&:document?) end # All the attachments that are documents for this model that has a collection. diff --git a/decidim-participatory_processes/app/cells/decidim/participatory_processes/content_blocks/highlighted_processes_cell.rb b/decidim-participatory_processes/app/cells/decidim/participatory_processes/content_blocks/highlighted_processes_cell.rb index e27352a98f7b9..6d9053e11269e 100644 --- a/decidim-participatory_processes/app/cells/decidim/participatory_processes/content_blocks/highlighted_processes_cell.rb +++ b/decidim-participatory_processes/app/cells/decidim/participatory_processes/content_blocks/highlighted_processes_cell.rb @@ -51,7 +51,7 @@ def highlighted_processes OrganizationPublishedParticipatoryProcesses.new(current_organization, current_user) | HighlightedParticipatoryProcesses.new | FilteredParticipatoryProcesses.new("active") - ).query.includes([:organization]).limit(highlighted_processes_max_results) + ).query.with_attached_hero_image.includes([:organization, :hero_image_attachment]).limit(highlighted_processes_max_results) end end From 66749a4becf2b6c8d9c08b9915d6bb5f72e83034 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Tue, 5 Apr 2022 16:50:46 +0200 Subject: [PATCH 2/2] Include author in upcoming_meetings query --- .../decidim/meetings/content_blocks/upcoming_meetings_cell.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decidim-meetings/app/cells/decidim/meetings/content_blocks/upcoming_meetings_cell.rb b/decidim-meetings/app/cells/decidim/meetings/content_blocks/upcoming_meetings_cell.rb index 955231abf31bb..3ac8bb65881b5 100644 --- a/decidim-meetings/app/cells/decidim/meetings/content_blocks/upcoming_meetings_cell.rb +++ b/decidim-meetings/app/cells/decidim/meetings/content_blocks/upcoming_meetings_cell.rb @@ -14,7 +14,7 @@ def show def upcoming_meetings @upcoming_meetings ||= Decidim::Meetings::Meeting - .includes(component: :participatory_space) + .includes(:author, component: :participatory_space) .where(component: meeting_components) .visible_for(current_user) .published