Skip to content

Commit

Permalink
Fix BURs/counts not including deleted posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nottalulah committed Oct 9, 2024
1 parent b958f4b commit bf8e99d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/counts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CountsController < ApplicationController
def posts
estimate_count = params.fetch(:estimate_count, "true").truthy?
skip_cache = params.fetch(:skip_cache, "false").truthy?
@count = PostQuery.normalize(params[:tags], current_user: CurrentUser.user, tag_limit: CurrentUser.user.tag_query_limit).fast_count(timeout: CurrentUser.statement_timeout, estimate_count: estimate_count, skip_cache: skip_cache)
@count = PostQuery.normalize(params[:tags], current_user: CurrentUser.user, tag_limit: CurrentUser.user.tag_query_limit, show_deleted: true).fast_count(timeout: CurrentUser.statement_timeout, estimate_count: estimate_count, skip_cache: skip_cache)

if request.format.xml?
respond_with({ posts: @count }, root: "counts")
Expand Down
16 changes: 12 additions & 4 deletions app/logical/post_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TagLimitError < Error; end
SINGLETON_METATAGS = ORDER_METATAGS + %w[limit random]

attr_reader :current_user
private attr_reader :tag_limit, :safe_mode, :builder
private attr_reader :tag_limit, :safe_mode, :builder, :show_deleted

delegate :tag?, :metatag?, :wildcard?, :metatags, :wildcards, :tag_names, :to_infix, :to_pretty_string, to: :ast
alias_method :safe_mode?, :safe_mode
Expand All @@ -47,7 +47,7 @@ def self.search(search, ...)
post_query.with_implicit_metatags.posts
end

def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe_mode: false)
def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe_mode: false, show_deleted: false)
if search_or_ast.is_a?(AST)
@ast = search_or_ast
else
Expand All @@ -57,6 +57,7 @@ def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe
@current_user = current_user
@tag_limit = tag_limit
@safe_mode = safe_mode
@show_deleted = show_deleted
end

# Build a new PostQuery from the given AST and the current settings.
Expand Down Expand Up @@ -223,7 +224,7 @@ def implicit_metatags
end

def show_deleted?
current_user.show_deleted_posts? || has_status_metatag?
show_deleted || current_user.show_deleted_posts? || has_status_metatag?
end

def has_status_metatag?
Expand All @@ -237,7 +238,14 @@ def has_status_metatag?

# @return [Integer, nil] The number of posts returned by the search, or nil on timeout.
def post_count
@post_count ||= fast_count
begin
old_show_deleted = @show_deleted
@show_deleted = true
@post_count ||= fast_count
ensure
@show_deleted = old_show_deleted
end
@post_count
end

# Return an estimate of the number of posts returned by the search. By default, we try to use an
Expand Down
1 change: 1 addition & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
password: SecureRandom.base64(32),
level: User::Levels::MODERATOR,
show_niche_posts: true,
show_deleted_posts: true,
)

0 comments on commit bf8e99d

Please sign in to comment.