From e133a598a3fc5a98363fec65cc192b9e5aba52c2 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Fri, 12 Oct 2018 15:17:32 -0700 Subject: [PATCH] fixes #3936 --- app/controllers/counts_controller.rb | 7 ++++++- app/models/post.rb | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/counts_controller.rb b/app/controllers/counts_controller.rb index 175983eed..795ec7d13 100644 --- a/app/controllers/counts_controller.rb +++ b/app/controllers/counts_controller.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index 54fdc3f27..31cdc7a91 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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)