Commit c9ea46745213b34c18ba53dae253eba290b47e1f
1 parent
3d567c77
Exists in
master
and in
28 other branches
Reorganizing the way we find tagged content
(ActionItem1553)
Showing
4 changed files
with
4 additions
and
11 deletions
Show diff stats
app/controllers/public/search_controller.rb
| ... | ... | @@ -226,7 +226,7 @@ class SearchController < PublicController |
| 226 | 226 | @tag = environment.tags.find_by_name(params[:tag]) |
| 227 | 227 | @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}" |
| 228 | 228 | if is_cache_expired?(@tag_cache_key, true) |
| 229 | - @tagged = environment.articles.find_tagged_with(@tag).paginate(:per_page => 10, :page => params[:npage]) | |
| 229 | + @tagged = environment.articles.find_tagged_with(@tag.name).paginate(:per_page => 10, :page => params[:npage]) | |
| 230 | 230 | end |
| 231 | 231 | end |
| 232 | 232 | ... | ... |
app/models/article.rb
| ... | ... | @@ -335,10 +335,6 @@ class Article < ActiveRecord::Base |
| 335 | 335 | $1 || '' |
| 336 | 336 | end |
| 337 | 337 | |
| 338 | - def self.find_tagged_with(tag) | |
| 339 | - self.find(:all, :include => :taggings, :conditions => ['taggings.tag_id = ?', tag.id]) | |
| 340 | - end | |
| 341 | - | |
| 342 | 338 | def creator |
| 343 | 339 | creator_id = versions[0][:last_changed_by_id] |
| 344 | 340 | creator_id && Profile.find(creator_id) | ... | ... |
app/models/profile.rb
| ... | ... | @@ -420,8 +420,7 @@ private :generate_url, :url_options |
| 420 | 420 | end |
| 421 | 421 | |
| 422 | 422 | def find_tagged_with(tag) |
| 423 | - # FIXME: this can be SLOW | |
| 424 | - articles.select {|item| item.tags.map(&:name).include?(tag) } | |
| 423 | + self.articles.find_tagged_with(tag) | |
| 425 | 424 | end |
| 426 | 425 | |
| 427 | 426 | # Tells whether a specified profile has members or nor. | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -729,8 +729,7 @@ class ArticleTest < Test::Unit::TestCase |
| 729 | 729 | |
| 730 | 730 | should 'get tagged with tag' do |
| 731 | 731 | a = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') |
| 732 | - t = a.tags[0] | |
| 733 | - as = Article.find_tagged_with(t) | |
| 732 | + as = Article.find_tagged_with('bli') | |
| 734 | 733 | |
| 735 | 734 | assert_includes as, a |
| 736 | 735 | end |
| ... | ... | @@ -742,8 +741,7 @@ class ArticleTest < Test::Unit::TestCase |
| 742 | 741 | user_from_other_environment = create_user('other_user', :environment => other_environment).person |
| 743 | 742 | article_from_other_enviroment = create(Article, :profile => user_from_other_environment, :tag_list => 'bli') |
| 744 | 743 | |
| 745 | - tag = article_from_other_enviroment.tags.first | |
| 746 | - tagged_articles_in_other_environment = other_environment.articles.find_tagged_with(tag) | |
| 744 | + tagged_articles_in_other_environment = other_environment.articles.find_tagged_with('bli') | |
| 747 | 745 | |
| 748 | 746 | assert_includes tagged_articles_in_other_environment, article_from_other_enviroment |
| 749 | 747 | assert_not_includes tagged_articles_in_other_environment, article_from_this_environment | ... | ... |