Permalink
Browse files

fix tag filtering

a story with tags [c, go] with a user's tag filter of [go] was just
removing the [go] tag from the story, not removing it from the list
completely
  • Loading branch information...
jcs committed Feb 7, 2013
1 parent 464b3c3 commit 95cdd886a10a0dbce31bdb8796aebbfade46a739
Showing with 13 additions and 9 deletions.
  1. +13 −9 app/controllers/home_controller.rb
@@ -124,22 +124,26 @@ def _find_stories_for_user_and_tag_and_newest_and_by_user(user, tag = nil,
conds.push user.id
end
filtered_tag_ids = []
if user
filtered_tag_ids = @user.tag_filters.map{|tf| tf.tag_id }
else
# for logged-out users, filter defaults
filtered_tag_ids = Tag.where(:filtered_by_default => true).map{|t| t.id }
end
if tag
conds[0] << "AND stories.id IN (SELECT taggings.story_id FROM " <<
"taggings WHERE taggings.tag_id = ?)"
conds.push tag.id
elsif by_user
conds[0] << "AND stories.user_id = ?"
conds.push by_user
elsif user
conds[0] += " AND taggings.tag_id NOT IN (SELECT tag_id FROM " <<
"tag_filters WHERE user_id = ?)"
conds.push @user.id
else
# for logged-out users, filter defaults
conds[0] += " AND taggings.tag_id NOT IN (SELECT id FROM " <<
"tags WHERE filtered_by_default = ?)"
conds.push true
elsif filtered_tag_ids.any?
conds[0] += " AND stories.id NOT IN (SELECT taggings.story_id " <<
"FROM taggings WHERE taggings.tag_id IN (" <<
filtered_tag_ids.map{|t| "?" }.join(",") << "))"
conds += filtered_tag_ids
end
stories = Story.find(

0 comments on commit 95cdd88

Please sign in to comment.