Avoid duplicate proposals with group on query. Avoid show successful proposals on recommendations.
This commit is contained in:
@@ -51,10 +51,10 @@ class Debate < ActiveRecord::Base
|
||||
debates_list = where("author_id != ?", user.id)
|
||||
debates_list_with_tagged = debates_list.joins(:tags).where('taggings.taggable_type = ?', self.name).where('tags.name IN (?)', user.interests)
|
||||
if debates_list_with_tagged.any?
|
||||
debates_list = debates_list_with_tagged
|
||||
debates_list = debates_list_with_tagged.group('debates.id')
|
||||
end
|
||||
|
||||
debates_list.uniq
|
||||
debates_list
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
|
||||
@@ -55,22 +55,23 @@ class Proposal < ActiveRecord::Base
|
||||
scope :retired, -> { where.not(retired_at: nil) }
|
||||
scope :not_retired, -> { where(retired_at: nil) }
|
||||
scope :successful, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success) }
|
||||
scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) }
|
||||
scope :public_for_api, -> { all }
|
||||
|
||||
def self.recommendations(user)
|
||||
proposals_list = where("author_id != ?", user.id)
|
||||
proposals_list = where("author_id != ?", user.id).unsuccessful
|
||||
proposals_list_with_tagged = self.proposals_with_tagged(user, proposals_list)
|
||||
|
||||
if proposals_list_with_tagged.any?
|
||||
proposals_list = self.proposals_not_followed_by_user(user, proposals_list_with_tagged)
|
||||
end
|
||||
|
||||
proposals_list.uniq
|
||||
proposals_list
|
||||
end
|
||||
|
||||
def self.proposals_with_tagged(user, proposals_list)
|
||||
proposals_list.joins(:tags).where('taggings.taggable_type = ?', self.name)
|
||||
.where('tags.name IN (?)', user.interests)
|
||||
.where('tags.name IN (?)', user.interests).group('proposals.id')
|
||||
end
|
||||
|
||||
def self.proposals_not_followed_by_user(user, proposals_list_with_tagged)
|
||||
|
||||
Reference in New Issue
Block a user