diff --git a/app/components/budgets/investments/votes_component.rb b/app/components/budgets/investments/votes_component.rb index 1350f5be6..e7e601c18 100644 --- a/app/components/budgets/investments/votes_component.rb +++ b/app/components/budgets/investments/votes_component.rb @@ -1,11 +1,10 @@ class Budgets::Investments::VotesComponent < ApplicationComponent - attr_reader :investment, :investment_votes + attr_reader :investment delegate :namespace, :current_user, :voted_for?, :image_absolute_url, :link_to_verify_account, :link_to_signin, :link_to_signup, to: :helpers - def initialize(investment, investment_votes: nil) + def initialize(investment) @investment = investment - @investment_votes = investment_votes end def vote_path @@ -28,11 +27,8 @@ class Budgets::Investments::VotesComponent < ApplicationComponent end def user_voted_for? - @user_voted_for ||= if investment_votes - voted_for?(investment_votes, investment) - else - current_user&.voted_for?(investment) - end + @user_voted_for = current_user&.voted_for?(investment) unless defined?(@user_voted_for) + @user_voted_for end def display_support_alert? diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 4f25c78a5..c0eec21bb 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -47,7 +47,6 @@ module Budgets @investment_ids = @investments.pluck(:id) @investments_map_coordinates = MapLocation.where(investment: investments).map(&:json_data) - load_investment_votes(@investments) @tag_cloud = tag_cloud @remote_translations = detect_remote_translations(@investments) end @@ -128,10 +127,6 @@ module Budgets "budget_investment" end - def load_investment_votes(investments) - @investment_votes = current_user ? current_user.budget_investment_votes(investments) : {} - end - def investment_params attributes = [:heading_id, :tag_list, :organization_name, :location, :terms_of_service, :related_sdg_list, diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 2cecdb6c3..ba32122fd 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -15,7 +15,6 @@ class Management::Budgets::InvestmentsController < Management::BaseController def index @investments = @investments.apply_filters_and_search(@budget, params).page(params[:page]) - load_investment_votes(@investments) end def new @@ -49,15 +48,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController def print @investments = @investments.apply_filters_and_search(@budget, params).order(cached_votes_up: :desc).for_render.limit(15) - load_investment_votes(@investments) end private - def load_investment_votes(investments) - @investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {} - end - def investment_params attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, image_attributes: image_attributes, diff --git a/app/models/user.rb b/app/models/user.rb index 15159f727..e6304a318 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -161,11 +161,6 @@ class User < ApplicationRecord voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } end - def budget_investment_votes(budget_investments) - voted = votes.for_budget_investments(budget_investments) - voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } - end - def comment_flags(comments) comment_flags = flags.for_comments(comments) comment_flags.each_with_object({}) { |f, h| h[f.flaggable_id] = true } diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index 79b6d8cf2..86c66d9fe 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -38,8 +38,7 @@
> - <%= render Budgets::Investments::VotesComponent.new(investment, - investment_votes: investment_votes) %> + <%= render Budgets::Investments::VotesComponent.new(investment) %>
<% elsif investment.should_show_vote_count? %>
<% end %> <% else %> diff --git a/app/views/management/budgets/investments/index.html.erb b/app/views/management/budgets/investments/index.html.erb index e44f904de..ad00520b7 100644 --- a/app/views/management/budgets/investments/index.html.erb +++ b/app/views/management/budgets/investments/index.html.erb @@ -21,7 +21,6 @@ <%= render "/budgets/investments/investment", investment: investment, investment_ids: @investment_ids, - investment_votes: @investment_votes, ballot: @ballot %> <% end %> diff --git a/app/views/management/budgets/investments/print.html.erb b/app/views/management/budgets/investments/print.html.erb index f6fcc4bab..f2ef18e22 100644 --- a/app/views/management/budgets/investments/print.html.erb +++ b/app/views/management/budgets/investments/print.html.erb @@ -26,7 +26,6 @@ <%= render "/budgets/investments/investment", investment: investment, investment_ids: @investment_ids, - investment_votes: @investment_votes, ballot: @ballot %> <% end %>