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 b8cdc7b..c737374 100644 --- a/lib/ext/community.rb +++ b/lib/ext/community.rb @@ -28,11 +28,14 @@ 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 def software? diff --git a/lib/ext/search_controller.rb b/lib/ext/search_controller.rb index c8bcc39..2a2856c 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 diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index 653140b..e10251b 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -24,7 +24,8 @@ class CommunitiesBlockTest < ActiveSupport::TestCase @software_info = nil end should "not have community of software or institution in block" do - assert_equal 1, @comminities_block.profile_list.count + assert_includes @comminities_block.profile_list, @community + assert_not_includes @comminities_block.profile_list, @software_info.community end end -- libgit2 0.21.2