From 113d8a0f28b662f5c1818107a58be65e39a9d86e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 2 Aug 2017 20:27:20 +0200 Subject: [PATCH] minor refactoring for proposal recommendations --- app/models/proposal.rb | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 1d3260b8a..f4bf1694d 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -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