Skip to content

Commit

Permalink
Proposals controller index optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
fblupi committed Nov 26, 2024
1 parent 213bace commit 08a7f17
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions config/initializers/decidim_overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 08a7f17

Please sign in to comment.