diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index e54299d90..bfa0eff4e 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -4,6 +4,7 @@ class PostsController < ApplicationController respond_to :html, :xml, :json rescue_from PostSets::SearchError, :with => :rescue_exception rescue_from Post::SearchError, :with => :rescue_exception + rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception def index @post_set = PostSets::Post.new(tag_query, params[:page], params[:limit]) diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index ecdf879c2..b4566c8f5 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -43,7 +43,15 @@ module PostSets end @posts ||= begin - temp = ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => per_page) + timeout = 3000 + if tag_string =~ /source:.*\*.*\*$/ + timeout = 300 + end + + temp = ::Post.with_timeout(timeout, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do + ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => per_page) + end + temp.all temp end diff --git a/app/models/post.rb b/app/models/post.rb index 5f99f645f..280e9bc90 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -152,7 +152,7 @@ class Post < ActiveRecord::Base module ImageMethods def has_large? - image_width > Danbooru.config.large_image_width + image_width.present? && image_width > Danbooru.config.large_image_width end def has_large