diff --git a/app/models/comment.rb b/app/models/comment.rb index e6f9a0af3..8e7c886a5 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -37,12 +37,7 @@ class Comment < ApplicationRecord scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :public_for_api, -> do not_valuations - .where(%{(comments.commentable_type = 'Debate' and comments.commentable_id in (?)) or - (comments.commentable_type = 'Proposal' and comments.commentable_id in (?)) or - (comments.commentable_type = 'Poll' and comments.commentable_id in (?))}, - Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id), - Poll.public_for_api.pluck(:id)) + .where(commentable: [Debate.public_for_api, Proposal.public_for_api, Poll.public_for_api]) end scope :sort_by_most_voted, -> { order(confidence_score: :desc, created_at: :desc) } diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index ffed3ab9f..a49dfe9a2 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -10,7 +10,7 @@ class ProposalNotification < ApplicationRecord validates :proposal, presence: true validate :minimum_interval - scope :public_for_api, -> { where(proposal_id: Proposal.public_for_api.pluck(:id)) } + scope :public_for_api, -> { where(proposal: Proposal.public_for_api) } scope :sort_by_created_at, -> { reorder(created_at: :desc) } scope :sort_by_moderated, -> { reorder(moderated: :desc) } diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index c7962b47a..372c3789f 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -5,12 +5,7 @@ ActsAsVotable::Vote.class_eval do belongs_to :budget_investment, foreign_key: "votable_id", class_name: "Budget::Investment" scope :public_for_api, -> do - where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or - (votes.votable_type = 'Proposal' and votes.votable_id in (?)) or - (votes.votable_type = 'Comment' and votes.votable_id in (?))}, - Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id), - Comment.public_for_api.pluck(:id)) + where(votable: [Debate.public_for_api, Proposal.public_for_api, Comment.public_for_api]) end def value