diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 52c114c2f..aaa5266b4 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -2,7 +2,8 @@ class CommentsController < ApplicationController respond_to :html, :xml, :json before_filter :member_only, :only => [:update, :create, :edit, :destroy] rescue_from User::PrivilegeError, :with => "static/access_denied" - + rescue_from ActiveRecord::StatementInvalid, :with => :search_error + def index if params[:group_by] == "comment" index_by_comment @@ -90,4 +91,16 @@ private raise User::PrivilegeError end end + +protected + + def search_error(e) + if e.message =~ /syntax error in tsquery/ + @error_message = "Meta-tags are not supported in comment searches by tag" + render :template => "static/error", :status => 500 + else + @exception = e + render :template => "static/error", :status => 500 + end + end end diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index a4c73aa32..e463bd33f 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -42,12 +42,21 @@ module PostSets raise SearchError.new("Upgrade your account to search more than two tags at once") end + timeout = 3000 + if tag_array.any? {|x| x =~ /^source:.*\*.*pixiv/} - raise SearchError.new("Your search took too long to execute and was canceled") + timeout = 300 end @posts ||= begin - temp = ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => per_page) + temp = ::Post.with_timeout(500, nil) do + ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => per_page) + end + + if temp.nil? + raise SearchError.new("Your search took too long to execute and was canceled") + end + temp.all temp end diff --git a/app/views/comments/search.html.erb b/app/views/comments/search.html.erb index d9e6db23c..8cf25759d 100644 --- a/app/views/comments/search.html.erb +++ b/app/views/comments/search.html.erb @@ -7,7 +7,7 @@ <%= search_field "body_matches", :label => "Body" %> <%= search_field "creator_name", :label => "User" %> - <%= search_field "post_tags_match", :label => "Tags" %> + <%= search_field "post_tags_match", :label => "Tags", :hint => "Meta-tags not supported" %> <%= submit_tag "Search" %> <% end %>