From b91ac453597168d3f0b13ab58f5b8519d7cb9825 Mon Sep 17 00:00:00 2001
From: tms <tmslft@gmail.com>
Date: Sat, 16 Feb 2013 16:33:51 -0500
Subject: [PATCH 1/2] Avoid grouping user stats by archetype (filter happens
 beforehand)

---
 app/models/user_action.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/models/user_action.rb b/app/models/user_action.rb
index 00cb87c0c..6d56f07f1 100644
--- a/app/models/user_action.rb
+++ b/app/models/user_action.rb
@@ -42,7 +42,7 @@ class UserAction < ActiveRecord::Base
     results = UserAction.select("action_type, COUNT(*) count, '' AS description")
       .joins(:target_topic)
       .where(user_id: user_id)
-      .group('action_type', 'topics.archetype')
+      .group('action_type')
 
     # should push this into the sql at some point, but its simple enough for now
     unless guardian.can_see_private_messages?(user_id)

From b7e392c7a372a99781fd882ce22a81010500f287 Mon Sep 17 00:00:00 2001
From: tms <tmslft@gmail.com>
Date: Sat, 16 Feb 2013 16:46:20 -0500
Subject: [PATCH 2/2] Don't count bookmark stats for users who can't see them

---
 app/models/user_action.rb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/app/models/user_action.rb b/app/models/user_action.rb
index 6d56f07f1..1ae9a929e 100644
--- a/app/models/user_action.rb
+++ b/app/models/user_action.rb
@@ -44,10 +44,14 @@ class UserAction < ActiveRecord::Base
       .where(user_id: user_id)
       .group('action_type')
 
-    # should push this into the sql at some point, but its simple enough for now
+    # We apply similar filters in stream, might consider trying to consolidate somehow
     unless guardian.can_see_private_messages?(user_id)
       results = results.where('topics.archetype <> ?', Archetype::private_message)
     end
+    
+    unless guardian.user && guardian.user.id == user_id
+      results = results.where("action_type <> ?", BOOKMARK)
+    end
 
     results = results.to_a