[Git][noosfero/noosfero][master] 2 commits: Fix suggestions of profiles that a user is already related

Rodrigo Souto gitlab at mg.gitlab.com
Fri Jun 16 10:55:33 BRT 2017


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
16b8b310 by pedrodelyra at 2017-06-13T17:07:23-03:00
Fix suggestions of profiles that a user is already related

- - - - -
d50465f6 by Rodrigo Souto at 2017-06-16T13:54:53+00:00
Merge branch 'fix_profile_suggestions' into 'master'

Fix suggestions of profiles that a user is already related

Closes #74

See merge request !1237
- - - - -


2 changed files:

- app/models/profile_suggestion.rb
- test/unit/profile_suggestion_test.rb


Changes:

=====================================
app/models/profile_suggestion.rb
=====================================
--- a/app/models/profile_suggestion.rb
+++ b/app/models/profile_suggestion.rb
@@ -115,8 +115,10 @@ class ProfileSuggestion < ApplicationRecord
     suggested_profiles = all_suggestions(person)
     return if suggested_profiles.nil?
 
-    already_suggested_profiles = person.suggested_profiles.map(&:suggestion_id).join(',')
-    suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present?
+    # Filter communities that person has already join and people that are already his friends.
+    suggested_profiles = suggested_profiles.where.not(id: person.memberships.map { |p| p.id } | person.friends.map { |f| f.id })
+    already_suggested_profiles = person.suggested_profiles
+    suggested_profiles = suggested_profiles.where.not(id: already_suggested_profiles)
     #TODO suggested_profiles = suggested_profiles.order('score DESC')
     suggested_profiles = suggested_profiles.limit(N_SUGGESTIONS)
     return if suggested_profiles.blank?


=====================================
test/unit/profile_suggestion_test.rb
=====================================
--- a/test/unit/profile_suggestion_test.rb
+++ b/test/unit/profile_suggestion_test.rb
@@ -59,8 +59,12 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
 
     suggestions = ProfileSuggestion.calculate_suggestions(p1)
 
-    assert_includes suggestions, p5
-    assert_includes suggestions, p6
+    assert_not_includes suggestions, p2
+    assert_not_includes suggestions, p3
+    assert_not_includes suggestions, p4
+
+    assert_includes     suggestions, p5
+    assert_includes     suggestions, p6
   end
 
   should 'calculate people with common_communities' do
@@ -84,10 +88,13 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
     c3.add_member(p4)
     c4.add_member(p5)
 
+    p1.add_friend(p2)
+    p2.add_friend(p1)
+
     suggestions = ProfileSuggestion.calculate_suggestions(p1)
 
-    assert_includes suggestions, p2
-    assert_includes suggestions, p4
+    assert_not_includes suggestions, p2
+    assert_includes     suggestions, p4
   end
 
   should 'calculate people with common_tags' do
@@ -127,10 +134,13 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
     a52.tag_list = ['onivorism', 'facism']
     a52.save!
 
+    p1.add_friend(p2)
+    p2.add_friend(p1)
+
     suggestions = ProfileSuggestion.calculate_suggestions(p1)
 
-    assert_includes suggestions, p2
-    assert_includes suggestions, p3
+    assert_not_includes suggestions, p2
+    assert_includes     suggestions, p3
   end
 
   should 'calculate communities with common_friends' do
@@ -155,10 +165,12 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
     c3.add_member(p2)
     c4.add_member(p3)
 
+    c1.add_member(p1)
+
     suggestions = ProfileSuggestion.calculate_suggestions(p1)
 
-    assert_includes suggestions, c1
-    assert_includes suggestions, c2
+    assert_not_includes suggestions, c1
+    assert_includes     suggestions, c2
   end
 
   should 'calculate communities with common_tags' do



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/42d13f4952a414cdc4933d7d34b7c6e525f13807...d50465f6267916874305e5909ffb5db8e7e4a9c5

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/42d13f4952a414cdc4933d7d34b7c6e525f13807...d50465f6267916874305e5909ffb5db8e7e4a9c5
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170616/20d256d0/attachment-0001.html>


More information about the Noosfero-dev mailing list