minor refactoring for proposal recommendations
This commit is contained in:
@@ -59,25 +59,14 @@ class Proposal < ActiveRecord::Base
|
||||
scope :public_for_api, -> { all }
|
||||
|
||||
def self.recommendations(user)
|
||||
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
|
||||
proposals_list.distinct
|
||||
tagged_with(user.interests, any: true).
|
||||
where("author_id != ?", user.id).
|
||||
unsuccessful.
|
||||
not_followed_by_user(user)
|
||||
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)
|
||||
end
|
||||
|
||||
def self.proposals_not_followed_by_user(user, proposals_list_with_tagged)
|
||||
followed_proposals_ids = Proposal.followed_by_user(user).pluck(:id)
|
||||
proposals_list_with_tagged.where("proposals.id NOT IN (?)", followed_proposals_ids)
|
||||
def self.not_followed_by_user(user)
|
||||
where.not(id: followed_by_user(user).pluck(:id))
|
||||
end
|
||||
|
||||
def to_param
|
||||
|
||||
Reference in New Issue
Block a user