diff --git a/lib/ext/communities_block.rb b/lib/ext/communities_block.rb index 5f986ea..d077e6d 100644 --- a/lib/ext/communities_block.rb +++ b/lib/ext/communities_block.rb @@ -4,10 +4,6 @@ class CommunitiesBlock def profile_list result = get_visible_profiles - valid_communities_string = Community.get_valid_communities_string - - result.each{|community| result.delete(community) unless eval(valid_communities_string)} - result.slice(0..get_limit-1) end @@ -21,6 +17,13 @@ class CommunitiesBlock visible_profiles = profiles.visible.includes( [:image,:domains,:preferred_domain,:environment] ) + + delete_communities = [] + valid_communities_string = Community.get_valid_communities_string + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} + + visible_profiles = visible_profiles.where(["profiles.id NOT IN (?)", delete_communities]) + if !prioritize_profiles_with_image return visible_profiles.all( :limit => get_limit, @@ -32,10 +35,11 @@ class CommunitiesBlock :order => 'profiles.updated_at DESC' ).sort_by {rand} else - return visible_profiles.with_image.sort_by {rand} + + visible_profiles = visible_profiles.with_image.sort_by {rand} + visible_profiles.without_image.all( :limit => get_limit * 5, :order => 'profiles.updated_at DESC' ).sort_by {rand} + return visible_profiles end end end diff --git a/lib/ext/community.rb b/lib/ext/community.rb index a657697..d274660 100644 --- a/lib/ext/community.rb +++ b/lib/ext/community.rb @@ -13,10 +13,13 @@ class Community def self.get_valid_communities_string remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/} - valid_communities_string = "" + valid_communities_string = "!(" remove_of_communities_methods.each do |method| - valid_communities_string += "!community.send('#{method}') && " + valid_communities_string += "community.send('#{method}') || " end - valid_communities_string[0..-5] + valid_communities_string = valid_communities_string[0..-5] + valid_communities_string += ")" + + valid_communities_string end end diff --git a/lib/ext/search_controller.rb b/lib/ext/search_controller.rb index 63cd989..45a0523 100644 --- a/lib/ext/search_controller.rb +++ b/lib/ext/search_controller.rb @@ -3,10 +3,12 @@ require_dependency 'search_controller' class SearchController def communities + delete_communities = [] valid_communities_string = Community.get_valid_communities_string + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} @scope = visible_profiles(Community) - @scope.each{|community| @scope.delete(community) unless eval(valid_communities_string)} + @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty? full_text_search end -- libgit2 0.21.2