Commit c45dca162c83ee8c81b4023729deed94ce63cb19
1 parent
db702524
Exists in
master
and in
22 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 | 70 | COMMON_TAGS = 2 |
71 | 71 | |
72 | 72 | def self.register_suggestions(person, suggested_profiles, rule) |
73 | + return if suggested_profiles.nil? | |
73 | 74 | already_suggested_profiles = person.profile_suggestions.map(&:suggestion_id).join(',') |
74 | 75 | suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present? |
75 | 76 | suggested_profiles = suggested_profiles.limit(SUGGESTIONS_BY_RULE) |
... | ... | @@ -95,7 +96,7 @@ class ProfileSuggestion < ActiveRecord::Base |
95 | 96 | |
96 | 97 | def self.people_with_common_friends(person) |
97 | 98 | person_friends = person.friends.map(&:id) |
98 | - return [] if person_friends.blank? | |
99 | + return if person_friends.blank? | |
99 | 100 | person.environment.people. |
100 | 101 | select("profiles.*, suggestions.count AS common_count"). |
101 | 102 | joins(" |
... | ... | @@ -109,7 +110,7 @@ class ProfileSuggestion < ActiveRecord::Base |
109 | 110 | |
110 | 111 | def self.people_with_common_communities(person) |
111 | 112 | person_communities = person.communities.map(&:id) |
112 | - return [] if person_communities.blank? | |
113 | + return if person_communities.blank? | |
113 | 114 | person.environment.people. |
114 | 115 | select("profiles.*, suggestions.count AS common_count"). |
115 | 116 | joins(" |
... | ... | @@ -125,7 +126,7 @@ class ProfileSuggestion < ActiveRecord::Base |
125 | 126 | |
126 | 127 | def self.people_with_common_tags(person) |
127 | 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 | 130 | person.environment.people. |
130 | 131 | select("profiles.*, suggestions.count as common_count"). |
131 | 132 | joins(" |
... | ... | @@ -143,7 +144,7 @@ class ProfileSuggestion < ActiveRecord::Base |
143 | 144 | |
144 | 145 | def self.communities_with_common_friends(person) |
145 | 146 | person_friends = person.friends.map(&:id) |
146 | - return [] if person_friends.blank? | |
147 | + return if person_friends.blank? | |
147 | 148 | person.environment.communities. |
148 | 149 | select("profiles.*, suggestions.count AS common_count"). |
149 | 150 | joins(" |
... | ... | @@ -159,7 +160,7 @@ class ProfileSuggestion < ActiveRecord::Base |
159 | 160 | |
160 | 161 | def self.communities_with_common_tags(person) |
161 | 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 | 164 | person.environment.communities. |
164 | 165 | select("profiles.*, suggestions.count AS common_count"). |
165 | 166 | joins(" | ... | ... |