diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 40034c0..56505c3 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -226,7 +226,7 @@ class SearchController < PublicController @tag = environment.tags.find_by_name(params[:tag]) @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}" if is_cache_expired?(@tag_cache_key, true) - @tagged = environment.articles.find_tagged_with(@tag).paginate(:per_page => 10, :page => params[:npage]) + @tagged = environment.articles.find_tagged_with(@tag.name).paginate(:per_page => 10, :page => params[:npage]) end end diff --git a/app/models/article.rb b/app/models/article.rb index 28a2ccb..9cfaf6c 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -335,10 +335,6 @@ class Article < ActiveRecord::Base $1 || '' end - def self.find_tagged_with(tag) - self.find(:all, :include => :taggings, :conditions => ['taggings.tag_id = ?', tag.id]) - end - def creator creator_id = versions[0][:last_changed_by_id] creator_id && Profile.find(creator_id) diff --git a/app/models/profile.rb b/app/models/profile.rb index 769d11d..cf5ca8d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -420,8 +420,7 @@ private :generate_url, :url_options end def find_tagged_with(tag) - # FIXME: this can be SLOW - articles.select {|item| item.tags.map(&:name).include?(tag) } + self.articles.find_tagged_with(tag) end # Tells whether a specified profile has members or nor. diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 346b291..9ed5c29 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -729,8 +729,7 @@ class ArticleTest < Test::Unit::TestCase should 'get tagged with tag' do a = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') - t = a.tags[0] - as = Article.find_tagged_with(t) + as = Article.find_tagged_with('bli') assert_includes as, a end @@ -742,8 +741,7 @@ class ArticleTest < Test::Unit::TestCase user_from_other_environment = create_user('other_user', :environment => other_environment).person article_from_other_enviroment = create(Article, :profile => user_from_other_environment, :tag_list => 'bli') - tag = article_from_other_enviroment.tags.first - tagged_articles_in_other_environment = other_environment.articles.find_tagged_with(tag) + tagged_articles_in_other_environment = other_environment.articles.find_tagged_with('bli') assert_includes tagged_articles_in_other_environment, article_from_other_enviroment assert_not_includes tagged_articles_in_other_environment, article_from_this_environment -- libgit2 0.21.2