Commit 4b1bc16ffea1791a2ec3988e1e8ee0a2a601c594
Exists in
master
and in
3 other branches
Merge branch 'fix_community_filter' into 'master'
Fix community filter See merge request !5
Showing
3 changed files
with
18 additions
and
9 deletions
Show diff stats
lib/ext/communities_block.rb
| @@ -4,10 +4,6 @@ class CommunitiesBlock | @@ -4,10 +4,6 @@ class CommunitiesBlock | ||
| 4 | 4 | ||
| 5 | def profile_list | 5 | def profile_list |
| 6 | result = get_visible_profiles | 6 | result = get_visible_profiles |
| 7 | - valid_communities_string = Community.get_valid_communities_string | ||
| 8 | - | ||
| 9 | - result.each{|community| result.delete(community) unless eval(valid_communities_string)} | ||
| 10 | - | ||
| 11 | result.slice(0..get_limit-1) | 7 | result.slice(0..get_limit-1) |
| 12 | end | 8 | end |
| 13 | 9 | ||
| @@ -21,6 +17,13 @@ class CommunitiesBlock | @@ -21,6 +17,13 @@ class CommunitiesBlock | ||
| 21 | visible_profiles = profiles.visible.includes( | 17 | visible_profiles = profiles.visible.includes( |
| 22 | [:image,:domains,:preferred_domain,:environment] | 18 | [:image,:domains,:preferred_domain,:environment] |
| 23 | ) | 19 | ) |
| 20 | + | ||
| 21 | + delete_communities = [] | ||
| 22 | + valid_communities_string = Community.get_valid_communities_string | ||
| 23 | + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} | ||
| 24 | + | ||
| 25 | + visible_profiles = visible_profiles.where(["profiles.id NOT IN (?)", delete_communities]) | ||
| 26 | + | ||
| 24 | if !prioritize_profiles_with_image | 27 | if !prioritize_profiles_with_image |
| 25 | return visible_profiles.all( | 28 | return visible_profiles.all( |
| 26 | :limit => get_limit, | 29 | :limit => get_limit, |
| @@ -32,10 +35,11 @@ class CommunitiesBlock | @@ -32,10 +35,11 @@ class CommunitiesBlock | ||
| 32 | :order => 'profiles.updated_at DESC' | 35 | :order => 'profiles.updated_at DESC' |
| 33 | ).sort_by {rand} | 36 | ).sort_by {rand} |
| 34 | else | 37 | else |
| 35 | - return visible_profiles.with_image.sort_by {rand} + | 38 | + visible_profiles = visible_profiles.with_image.sort_by {rand} + |
| 36 | visible_profiles.without_image.all( | 39 | visible_profiles.without_image.all( |
| 37 | :limit => get_limit * 5, :order => 'profiles.updated_at DESC' | 40 | :limit => get_limit * 5, :order => 'profiles.updated_at DESC' |
| 38 | ).sort_by {rand} | 41 | ).sort_by {rand} |
| 42 | + return visible_profiles | ||
| 39 | end | 43 | end |
| 40 | end | 44 | end |
| 41 | end | 45 | end |
lib/ext/community.rb
| @@ -13,10 +13,13 @@ class Community | @@ -13,10 +13,13 @@ class Community | ||
| 13 | 13 | ||
| 14 | def self.get_valid_communities_string | 14 | def self.get_valid_communities_string |
| 15 | remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/} | 15 | remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/} |
| 16 | - valid_communities_string = "" | 16 | + valid_communities_string = "!(" |
| 17 | remove_of_communities_methods.each do |method| | 17 | remove_of_communities_methods.each do |method| |
| 18 | - valid_communities_string += "!community.send('#{method}') && " | 18 | + valid_communities_string += "community.send('#{method}') || " |
| 19 | end | 19 | end |
| 20 | - valid_communities_string[0..-5] | 20 | + valid_communities_string = valid_communities_string[0..-5] |
| 21 | + valid_communities_string += ")" | ||
| 22 | + | ||
| 23 | + valid_communities_string | ||
| 21 | end | 24 | end |
| 22 | end | 25 | end |
lib/ext/search_controller.rb
| @@ -3,10 +3,12 @@ require_dependency 'search_controller' | @@ -3,10 +3,12 @@ require_dependency 'search_controller' | ||
| 3 | class SearchController | 3 | class SearchController |
| 4 | 4 | ||
| 5 | def communities | 5 | def communities |
| 6 | + delete_communities = [] | ||
| 6 | valid_communities_string = Community.get_valid_communities_string | 7 | valid_communities_string = Community.get_valid_communities_string |
| 8 | + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} | ||
| 7 | 9 | ||
| 8 | @scope = visible_profiles(Community) | 10 | @scope = visible_profiles(Community) |
| 9 | - @scope.each{|community| @scope.delete(community) unless eval(valid_communities_string)} | 11 | + @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty? |
| 10 | 12 | ||
| 11 | full_text_search | 13 | full_text_search |
| 12 | end | 14 | end |