Commit c45dca162c83ee8c81b4023729deed94ce63cb19
1 parent
db702524
Exists in
master
and in
21 other branches
profile-suggestions: avoid problems with empty results
Showing
1 changed file
with
6 additions
and
5 deletions
Show diff stats
app/models/profile_suggestion.rb
| @@ -70,6 +70,7 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -70,6 +70,7 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 70 | COMMON_TAGS = 2 | 70 | COMMON_TAGS = 2 |
| 71 | 71 | ||
| 72 | def self.register_suggestions(person, suggested_profiles, rule) | 72 | def self.register_suggestions(person, suggested_profiles, rule) |
| 73 | + return if suggested_profiles.nil? | ||
| 73 | already_suggested_profiles = person.profile_suggestions.map(&:suggestion_id).join(',') | 74 | already_suggested_profiles = person.profile_suggestions.map(&:suggestion_id).join(',') |
| 74 | suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present? | 75 | suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present? |
| 75 | suggested_profiles = suggested_profiles.limit(SUGGESTIONS_BY_RULE) | 76 | suggested_profiles = suggested_profiles.limit(SUGGESTIONS_BY_RULE) |
| @@ -95,7 +96,7 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -95,7 +96,7 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 95 | 96 | ||
| 96 | def self.people_with_common_friends(person) | 97 | def self.people_with_common_friends(person) |
| 97 | person_friends = person.friends.map(&:id) | 98 | person_friends = person.friends.map(&:id) |
| 98 | - return [] if person_friends.blank? | 99 | + return if person_friends.blank? |
| 99 | person.environment.people. | 100 | person.environment.people. |
| 100 | select("profiles.*, suggestions.count AS common_count"). | 101 | select("profiles.*, suggestions.count AS common_count"). |
| 101 | joins(" | 102 | joins(" |
| @@ -109,7 +110,7 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -109,7 +110,7 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 109 | 110 | ||
| 110 | def self.people_with_common_communities(person) | 111 | def self.people_with_common_communities(person) |
| 111 | person_communities = person.communities.map(&:id) | 112 | person_communities = person.communities.map(&:id) |
| 112 | - return [] if person_communities.blank? | 113 | + return if person_communities.blank? |
| 113 | person.environment.people. | 114 | person.environment.people. |
| 114 | select("profiles.*, suggestions.count AS common_count"). | 115 | select("profiles.*, suggestions.count AS common_count"). |
| 115 | joins(" | 116 | joins(" |
| @@ -125,7 +126,7 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -125,7 +126,7 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 125 | 126 | ||
| 126 | def self.people_with_common_tags(person) | 127 | def self.people_with_common_tags(person) |
| 127 | profile_tags = person.articles.select('tags.id').joins(:tags).map(&:id) | 128 | profile_tags = person.articles.select('tags.id').joins(:tags).map(&:id) |
| 128 | - return [] if profile_tags.blank? | 129 | + return if profile_tags.blank? |
| 129 | person.environment.people. | 130 | person.environment.people. |
| 130 | select("profiles.*, suggestions.count as common_count"). | 131 | select("profiles.*, suggestions.count as common_count"). |
| 131 | joins(" | 132 | joins(" |
| @@ -143,7 +144,7 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -143,7 +144,7 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 143 | 144 | ||
| 144 | def self.communities_with_common_friends(person) | 145 | def self.communities_with_common_friends(person) |
| 145 | person_friends = person.friends.map(&:id) | 146 | person_friends = person.friends.map(&:id) |
| 146 | - return [] if person_friends.blank? | 147 | + return if person_friends.blank? |
| 147 | person.environment.communities. | 148 | person.environment.communities. |
| 148 | select("profiles.*, suggestions.count AS common_count"). | 149 | select("profiles.*, suggestions.count AS common_count"). |
| 149 | joins(" | 150 | joins(" |
| @@ -159,7 +160,7 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -159,7 +160,7 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 159 | 160 | ||
| 160 | def self.communities_with_common_tags(person) | 161 | def self.communities_with_common_tags(person) |
| 161 | profile_tags = person.articles.select('tags.id').joins(:tags).map(&:id) | 162 | profile_tags = person.articles.select('tags.id').joins(:tags).map(&:id) |
| 162 | - return [] if profile_tags.blank? | 163 | + return if profile_tags.blank? |
| 163 | person.environment.communities. | 164 | person.environment.communities. |
| 164 | select("profiles.*, suggestions.count AS common_count"). | 165 | select("profiles.*, suggestions.count AS common_count"). |
| 165 | joins(" | 166 | joins(" |