Skip to content

Commit 33f04c1

Browse files
committed
Only count posts visible to user
1 parent 08dab30 commit 33f04c1

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

app/controllers/users_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ def show
5050
@posts = set_posts.user_sort({ term: params[:sort], default: :score },
5151
age: :created_at, score: :score)
5252

53-
@total_post_count = Post.all.by(@user).count
53+
@total_post_count = if @user == current_user || current_user&.at_least_moderator?
54+
Post.all.by(@user).count
55+
else
56+
Post.all.by(@user)
57+
.undeleted
58+
.joins(:category)
59+
.where('categories.min_view_trust_level <= ?', current_user&.trust_level || 0)
60+
.count
61+
end
5462
@posts = @posts.first(@limit)
5563
render layout: 'without_sidebar'
5664
end

app/models/category.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def self.accessible_to(user)
7272
end
7373

7474
trust_level = user&.trust_level || 0
75-
Category.where('IFNULL(min_view_trust_level, -1) <= ?', trust_level)
75+
Category.where('min_view_trust_level <= ?', trust_level)
7676
end
7777

7878
# Gets category matching a given name

0 commit comments

Comments
 (0)