From 566517ee58d1fbf378683c20ed59db3346026fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Bol=C3=ADvar?= Date: Mon, 25 Nov 2024 17:14:19 +0100 Subject: [PATCH 1/6] Proposal index page performance improvements (#583) --- app/views/decidim/proposals/index.html.erb | 44 ++++++++++++++++++++++ config/initializers/decidim_overrides.rb | 4 ++ spec/lib/overrides_spec.rb | 5 ++- spec/system/assemblies_spec.rb | 1 - 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 app/views/decidim/proposals/index.html.erb diff --git a/app/views/decidim/proposals/index.html.erb b/app/views/decidim/proposals/index.html.erb new file mode 100644 index 000000000..ae692e0cf --- /dev/null +++ b/app/views/decidim/proposals/index.html.erb @@ -0,0 +1,44 @@ +<% add_decidim_page_title(t("name", scope: "decidim.components.proposals")) %> + +<% append_stylesheet_pack_tag "decidim_proposals", media: "all" %> +<% append_javascript_pack_tag "decidim_proposals" %> + +<% content_for :aside do %> +

<%= component_name %>

+ +
+ <% if current_settings.creation_enabled && current_component.participatory_space.can_participate?(current_user) %> + <%= action_authorized_link_to :create, new_proposal_path, class: "button button__xl button__secondary w-full", data: { "redirect_url" => new_proposal_path } do %> + <%= t("new_proposal", scope: "decidim.proposals.proposals.index") %> + <%= icon "add-line" %> + <% end %> + <% end %> + + <% if component_settings.collaborative_drafts_enabled? %> + <%= link_to collaborative_drafts_path, class: "button button__sm button__transparent-secondary" do %> + <%= t("collaborative_drafts_list", scope: "decidim.proposals.proposals.index") %> + <%= icon "edit-2-line" %> + <% end %> + <% end %> +
+ + <%= render layout: "decidim/shared/filters", locals: { filter_sections: , search_variable: :search_text_cont, skip_to_id: "proposals" } do %> + <%= hidden_field_tag :order, order, id: nil, class: "order_filter" %> + <% end %> +<% end %> + +<%= render layout: "layouts/decidim/shared/layout_two_col" do %> + + <%= render partial: "decidim/shared/component_announcement" %> + + <% if show_voting_rules? %> +
+ <%= render partial: "voting_rules" %> +
+ <% end %> + +
+ <%= render partial: "proposals" %> +
+ +<% end %> diff --git a/config/initializers/decidim_overrides.rb b/config/initializers/decidim_overrides.rb index 3df4c8b2c..715baea53 100644 --- a/config/initializers/decidim_overrides.rb +++ b/config/initializers/decidim_overrides.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true Rails.application.config.to_prepare do + default_options = Decidim::Paginable::OPTIONS + Decidim::Paginable.send(:remove_const, :OPTIONS) + Decidim::Paginable::OPTIONS = (default_options + [10]).uniq.sort.freeze + Decidim::PaginateHelper.include(Decidim::PaginateHelperOverride) Decidim::Initiatives::Admin::Permissions.prepend(Decidim::Initiatives::Admin::PermissionsOverride) Decidim::SearchResourceFieldsMapper.prepend(Decidim::Overrides::SearchResourceFieldsMapper) diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index 26b3da048..6c1d6db07 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -11,7 +11,7 @@ files: { "/app/helpers/decidim/paginate_helper.rb" => "6fd69359386319d678c7a17cf64de4d9", "/app/controllers/decidim/application_controller.rb" => "e86fe37834b061828536f9417fe56cd1", # ephemeral participation overrides - "/app/controllers/concerns/decidim/paginable.rb" => "a42381a0883c92df189ac61cebea3047", # update per_page method in assemblies_controller_override.rb + "/app/controllers/concerns/decidim/paginable.rb" => "a42381a0883c92df189ac61cebea3047", # update per_page method in assemblies_controller_override.rb and include 10 in OPTIONS constant "/app/helpers/decidim/decidim_form_helper.rb" => "c534a1faa8da83aab5b2190f9d7534c3", # ephemeral participation overrides "/app/models/decidim/component.rb" => "ec2a03817027336392f1e9e0893309ab", # ephemeral participation overrides "/app/models/decidim/organization.rb" => "04eaf4467a1e0d891251c5cedf71f5e4", # ephemeral participation overrides @@ -115,7 +115,8 @@ package: "decidim-proposals", files: { "/app/helpers/decidim/proposals/application_helper.rb" => "c17dd875a166cd0cd3c09b0e596ebef5", - "/app/presenters/decidim/proposals/proposal_presenter.rb" => "bbc7cee02125c1f8cf909219e48af337" + "/app/presenters/decidim/proposals/proposal_presenter.rb" => "bbc7cee02125c1f8cf909219e48af337", + "/app/views/decidim/proposals/proposals/index.html.erb" => "48b62ae409b6ed736375772946ef2aa9" # remove map from index page } }, { diff --git a/spec/system/assemblies_spec.rb b/spec/system/assemblies_spec.rb index ddb269857..432fe4a19 100644 --- a/spec/system/assemblies_spec.rb +++ b/spec/system/assemblies_spec.rb @@ -20,7 +20,6 @@ it "lists 25 assemblies per page" do within "#assemblies-grid" do - expect(page).to have_content("Results per page:\n25") expect(page).to have_css("[id^=assembly_]", count: 25) end end From 2252e52421ff0182db43abad3829890c8f8bae29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Bol=C3=ADvar?= Date: Tue, 26 Nov 2024 14:14:46 +0100 Subject: [PATCH 2/6] Bump `decidim-internal_evaluation` module (#584) --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index bf8fbf1f3..e85c9bdf8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -181,7 +181,7 @@ GIT GIT remote: https://github.com/AjuntamentdeBarcelona/decidim-internal-evaluation-module - revision: cf5eb7f00f957881ade8360a69655e92d95ceff0 + revision: 9c656bb021c5e2ee055c9686e43c880566d4cef1 branch: release/0.28-stable specs: decidim-internal_evaluation (0.0.1) From 7c4291a7df33d178a1af8cd10b060ad5612ff229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bol=C3=ADvar?= Date: Tue, 26 Nov 2024 14:25:01 +0100 Subject: [PATCH 3/6] Remove last activity from menu and tooltip from author cell --- app/cells/decidim/author/show.erb | 26 +++++++++++++++++++ .../show.erb | 8 ++++++ .../_menu_breadcrumb_main_dropdown.html.erb | 13 ++++++++++ spec/lib/overrides_spec.rb | 5 +++- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/cells/decidim/author/show.erb create mode 100644 app/cells/decidim/participatory_space_dropdown_metadata/show.erb create mode 100644 app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown.html.erb diff --git a/app/cells/decidim/author/show.erb b/app/cells/decidim/author/show.erb new file mode 100644 index 000000000..ae7ffe7b3 --- /dev/null +++ b/app/cells/decidim/author/show.erb @@ -0,0 +1,26 @@ + + <%= content_tag :span, class: "author__container#{" is-compact" if layout == :compact}" do %> + <% if layout == :compact %> + <%= render :avatar %> + + + <%= render :name %> + + <% context_actions.each do |action| %> + <%= render action %> + <% end %> + + <% elsif layout == :avatar %> + <%= render :avatar %> + <% else %> + <%= render :avatar %> + <%= render :name %> + <% end %> + <% end %> + + <% if layout == :default %> + <% context_actions.each do |action| %> + <%= render action %> + <% end %> + <% end %> + diff --git a/app/cells/decidim/participatory_space_dropdown_metadata/show.erb b/app/cells/decidim/participatory_space_dropdown_metadata/show.erb new file mode 100644 index 000000000..fe402f151 --- /dev/null +++ b/app/cells/decidim/participatory_space_dropdown_metadata/show.erb @@ -0,0 +1,8 @@ + diff --git a/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown.html.erb b/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown.html.erb new file mode 100644 index 000000000..c504e03e0 --- /dev/null +++ b/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown.html.erb @@ -0,0 +1,13 @@ + diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index 6c1d6db07..1e5e90fa2 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -28,7 +28,10 @@ "/app/cells/decidim/activities_cell.rb" => "dd17416a8d1efe7f26b1e759613e4db4", "/app/cells/decidim/user_profile_cell.rb" => "71216a17c7eea8dd8ebc1ea3907efaef", "/lib/decidim/search_resource_fields_mapper.rb" => "ff2cc476eb72c2942cf2e69ae21b84fa", - "/app/views/layouts/decidim/header/_main.html.erb" => "a6496ec11e073062743a927ee3c8bd3c" + "/app/views/layouts/decidim/header/_main.html.erb" => "a6496ec11e073062743a927ee3c8bd3c", + "/app/cells/decidim/participatory_space_dropdown_metadata/show.erb" => "e1546b7776a0e1fffdbef705094c189d", # delete last activity + "/app/cells/decidim/author/show.erb" => "20bdef8a694a2dcb70202ac7f017060d", # remove tooltip + "/app/views/layouts/decidim/header/_menu_breadcrumb_main_dropdown.html.erb" => "494b33a9fc70f859f766962815399445" # delete last activity } }, { From 57f963badf41de9ad9baefec59eb87307b03038e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bol=C3=ADvar?= Date: Tue, 26 Nov 2024 15:48:50 +0100 Subject: [PATCH 4/6] Uninstall decidim-kids --- Gemfile | 1 - Gemfile.lock | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/Gemfile b/Gemfile index 46235f26d..f1e36aa49 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,6 @@ gem "decidim-stats", path: "decidim-stats" gem "decidim-decidim_awesome", git: "https://github.com/decidim-ice/decidim-module-decidim_awesome" gem "decidim-internal_evaluation", git: "https://github.com/AjuntamentdeBarcelona/decidim-internal-evaluation-module", branch: "release/0.28-stable" -gem "decidim-kids", git: "https://github.com/AjuntamentdeBarcelona/decidim-module-kids" gem "decidim-navigation_maps", git: "https://github.com/Platoniq/decidim-module-navigation_maps" gem "decidim-term_customizer", git: "https://github.com/mainio/decidim-module-term_customizer" gem "decidim-vocdoni", git: "https://github.com/decidim-vocdoni/decidim-module-vocdoni" diff --git a/Gemfile.lock b/Gemfile.lock index e85c9bdf8..fb8ccaacd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -190,16 +190,6 @@ GIT decidim-templates (~> 0.28.0) deface (~> 1.9) -GIT - remote: https://github.com/AjuntamentdeBarcelona/decidim-module-kids - revision: df16cf4de13c306348761d850d19815c8221874e - specs: - decidim-kids (0.2.0) - decidim-core (>= 0.28, < 0.29) - decidim-system (>= 0.28, < 0.29) - decidim-verifications (>= 0.28, < 0.29) - deface (>= 1.5) - GIT remote: https://github.com/Platoniq/decidim-module-navigation_maps revision: 7fd50e1368bae4c7955c0ba8ec5ee395273a5329 @@ -1004,7 +994,6 @@ DEPENDENCIES decidim-ephemeral_participation! decidim-initiatives! decidim-internal_evaluation! - decidim-kids! decidim-navigation_maps! decidim-sortitions! decidim-stats! From 213bace539df7bd31ce8b7b5f469072a503471d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bol=C3=ADvar?= Date: Tue, 26 Nov 2024 12:41:55 +0100 Subject: [PATCH 5/6] Uninstall puma_worker_killer --- Gemfile | 1 - Gemfile.lock | 6 ------ config/puma.rb | 6 ------ 3 files changed, 13 deletions(-) diff --git a/Gemfile b/Gemfile index f1e36aa49..d1150ec3f 100644 --- a/Gemfile +++ b/Gemfile @@ -53,7 +53,6 @@ group :production do gem "dalli" gem "lograge" gem "matrix" - gem "puma_worker_killer" # Used to restart puma workers every 6h and free memory gem "rack_password" gem "rack-ssl-enforcer" gem "rack-timeout" # Let's kill long-running requests after the Heroku router has responded to diff --git a/Gemfile.lock b/Gemfile.lock index fb8ccaacd..a8e004352 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -504,8 +504,6 @@ GEM base64 (>= 0.1.0) csv (>= 3.0.0) geom2d (0.4.1) - get_process_mem (0.2.7) - ffi (~> 1.0) globalid (1.2.1) activesupport (>= 6.1) graphql (2.0.31) @@ -711,9 +709,6 @@ GEM public_suffix (6.0.1) puma (6.4.2) nio4r (~> 2.0) - puma_worker_killer (0.3.1) - get_process_mem (~> 0.2) - puma (>= 2.7) racc (1.8.1) rack (2.2.10) rack-attack (6.7.0) @@ -1011,7 +1006,6 @@ DEPENDENCIES origami progressbar puma - puma_worker_killer rack-ssl-enforcer rack-timeout rack_password diff --git a/config/puma.rb b/config/puma.rb index 6ce5169b9..e49936482 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -9,9 +9,3 @@ port ENV.fetch("PORT", nil) || 3000 environment ENV.fetch("RACK_ENV", nil) || "development" - -before_fork do - require "puma_worker_killer" - - PumaWorkerKiller.enable_rolling_restart -end From 08a7f17d05215ef546ba315819ec7fb414f5601c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bol=C3=ADvar?= Date: Tue, 26 Nov 2024 16:40:09 +0100 Subject: [PATCH 6/6] Proposals controller index optimization --- .../proposals_controller_override.rb | 44 +++++++++++++++++++ config/initializers/decidim_overrides.rb | 1 + spec/lib/overrides_spec.rb | 1 + 3 files changed, 46 insertions(+) create mode 100644 app/controllers/concerns/decidim/proposals/proposals_controller_override.rb diff --git a/app/controllers/concerns/decidim/proposals/proposals_controller_override.rb b/app/controllers/concerns/decidim/proposals/proposals_controller_override.rb new file mode 100644 index 000000000..08d6ce00e --- /dev/null +++ b/app/controllers/concerns/decidim/proposals/proposals_controller_override.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Decidim + module Proposals + module ProposalsControllerOverride + extend ActiveSupport::Concern + + included do + def index + if component_settings.participatory_texts_enabled? + @proposals = Decidim::Proposals::Proposal + .where(component: current_component) + .published + .not_hidden + .only_amendables + .includes(:category, :scope, :attachments, :coauthorships) + .order(position: :asc) + render "decidim/proposals/proposals/participatory_texts/participatory_text" + else + @proposals = search + .result + .published + .not_hidden + + @all_geocoded_proposals = @proposals.geocoded + + @proposals = reorder(@proposals) + @proposals = paginate(@proposals) + @proposals = @proposals.includes(:component, :coauthorships, :attachments) + + @voted_proposals = if current_user + ProposalVote.where( + author: current_user, + proposal: @proposals.pluck(:id) + ).pluck(:decidim_proposal_id) + else + [] + end + end + end + end + end + end +end diff --git a/config/initializers/decidim_overrides.rb b/config/initializers/decidim_overrides.rb index 715baea53..f7a46792e 100644 --- a/config/initializers/decidim_overrides.rb +++ b/config/initializers/decidim_overrides.rb @@ -26,4 +26,5 @@ Decidim::Forms::QuestionnaireUserAnswers.include(Decidim::Forms::QuestionnaireUserAnswersOverride) Decidim::Proposals::ApplicationHelper.include(Decidim::Proposals::ApplicationHelperOverride) Decidim::Assemblies::AssembliesController.include(Decidim::Assemblies::AssembliesControllerOverride) + Decidim::Proposals::ProposalsController.include(Decidim::Proposals::ProposalsControllerOverride) end diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index 1e5e90fa2..6d53ba854 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -117,6 +117,7 @@ { package: "decidim-proposals", files: { + "/app/controllers/decidim/proposals/proposals_controller.rb" => "69420e7f27e1e7cb2688dadcc91017b3", "/app/helpers/decidim/proposals/application_helper.rb" => "c17dd875a166cd0cd3c09b0e596ebef5", "/app/presenters/decidim/proposals/proposal_presenter.rb" => "bbc7cee02125c1f8cf909219e48af337", "/app/views/decidim/proposals/proposals/index.html.erb" => "48b62ae409b6ed736375772946ef2aa9" # remove map from index page