Commit 96cafca2a0645d4bf41b132fab3f83a22cc5e8e0

Authored by Luciano Prestes
1 parent 503946ee

Fix bug on filter communities

lib/ext/communities_block.rb
... ... @@ -4,10 +4,6 @@ class CommunitiesBlock
4 4  
5 5 def profile_list
6 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 7 result.slice(0..get_limit-1)
12 8 end
13 9  
... ... @@ -21,6 +17,13 @@ class CommunitiesBlock
21 17 visible_profiles = profiles.visible.includes(
22 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 27 if !prioritize_profiles_with_image
25 28 return visible_profiles.all(
26 29 :limit => get_limit,
... ... @@ -32,10 +35,11 @@ class CommunitiesBlock
32 35 :order => 'profiles.updated_at DESC'
33 36 ).sort_by {rand}
34 37 else
35   - return visible_profiles.with_image.sort_by {rand} +
  38 + visible_profiles = visible_profiles.with_image.sort_by {rand} +
36 39 visible_profiles.without_image.all(
37 40 :limit => get_limit * 5, :order => 'profiles.updated_at DESC'
38 41 ).sort_by {rand}
  42 + return visible_profiles
39 43 end
40 44 end
41 45 end
... ...
lib/ext/community.rb
... ... @@ -13,10 +13,13 @@ class Community
13 13  
14 14 def self.get_valid_communities_string
15 15 remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/}
16   - valid_communities_string = ""
  16 + valid_communities_string = "!("
17 17 remove_of_communities_methods.each do |method|
18   - valid_communities_string += "!community.send('#{method}') && "
  18 + valid_communities_string += "community.send('#{method}') || "
19 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 24 end
22 25 end
... ...
lib/ext/search_controller.rb
... ... @@ -3,10 +3,12 @@ require_dependency &#39;search_controller&#39;
3 3 class SearchController
4 4  
5 5 def communities
  6 + delete_communities = []
6 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 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 13 full_text_search
12 14 end
... ...