This commit is contained in:
Albert Yi
2018-10-12 15:17:32 -07:00
parent a85f3773e3
commit e133a598a3
2 changed files with 12 additions and 6 deletions

View File

@@ -3,6 +3,11 @@ class CountsController < ApplicationController
rescue_from Post::TimeoutError, with: :rescue_exception
def posts
@count = Post.fast_count(params[:tags], raise_on_timeout: true)
@count = Post.fast_count(
params[:tags],
timeout: CurrentUser.statement_timeout,
raise_on_timeout: true,
skip_cache: params[:skip_cache]
)
end
end

View File

@@ -1155,7 +1155,7 @@ class Post < ApplicationRecord
end
module CountMethods
def fast_count(tags = "", timeout: 1_000, raise_on_timeout: false)
def fast_count(tags = "", timeout: 1_000, raise_on_timeout: false, skip_cache: false)
tags = tags.to_s
tags += " rating:s" if CurrentUser.safe_mode?
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && !Tag.has_metatag?(tags, "status", "-status")
@@ -1176,13 +1176,14 @@ class Post < ApplicationRecord
elsif tags =~ /^rating:e(?:xplicit)?$/
return (Post.maximum(:id) * (201650.0 / 2200402)).floor
elsif tags =~ /status:deleted.status:deleted/
# temp fix for degenerate crawlers
return 0
end
end
count = get_count_from_cache(tags)
count = nil
unless skip_cache
count = get_count_from_cache(tags)
end
if count.nil?
count = fast_count_search(tags, timeout: timeout, raise_on_timeout: raise_on_timeout)