should solve all residual tag_query_limit bugs

This commit is contained in:
albert
2013-02-20 21:56:09 -05:00
parent 2f180036e2
commit e51631fbfa
8 changed files with 45 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
class DelayedJobsController < ApplicationController
def index
@delayed_jobs = Delayed::Job.where("handler not like ? and handler not like ?", "%method_name: :update_related%", "%method_name: :process!%").order("created_at desc").paginate(params[:page])
@delayed_jobs = Delayed::Job.order("created_at desc").paginate(params[:page])
end
end

View File

@@ -0,0 +1,23 @@
module DelayedJobsHelper
def print_handler(job)
case job.name
when "Upload#process!"
'<strong>upload post</strong>: <a href="/uploads/' + job.payload_object.object.id.to_s + '">record</a>'
when "Tag#update_related"
"none"
when "TagAlias#process!"
'<strong>alias</strong>: ' + job.payload_object.antecedent_name + " -&gt; " + job.payload_object.consequent_name
when "TagImplication#process!"
'<strong>implication</strong>: ' + job.payload_object.antecedent_name + " -&gt; " + job.payload_object.consequent_name
when "TagAlias#clear_cache"
"none"
else
job.handler
end
end
end

View File

@@ -49,24 +49,28 @@ class PostQueryBuilder
"''" + escaped_token + "''"
end
end
def tag_query_limit
Danbooru.config.tag_query_limit
end
def add_tag_string_search_relation(tags, relation)
tag_query_sql = []
if tags[:include].any?
raise ::Post::SearchError.new("You cannot search for more than #{CurrentUser.user.tag_query_limit} tags at a time") if tags[:include].size > CurrentUser.user.tag_query_limit
raise ::Post::SearchError.new("You cannot search for more than #{tag_query_limit} tags at a time") if tags[:include].size > tag_query_limit
tag_query_sql << "(" + escape_string_for_tsquery(tags[:include]).join(" | ") + ")"
has_constraints!
end
if tags[:related].any?
raise ::Post::SearchError.new("You cannot search for more than #{CurrentUser.user.tag_query_limit} tags at a time") if tags[:related].size > CurrentUser.user.tag_query_limit
raise ::Post::SearchError.new("You cannot search for more than #{tag_query_limit} tags at a time") if tags[:related].size > tag_query_limit
tag_query_sql << "(" + escape_string_for_tsquery(tags[:related]).join(" & ") + ")"
has_constraints!
end
if tags[:exclude].any?
raise ::Post::SearchError.new("You cannot search for more than #{CurrentUser.user.tag_query_limit} tags at a time") if tags[:exclude].size > CurrentUser.user.tag_query_limit
raise ::Post::SearchError.new("You cannot search for more than #{tag_query_limit} tags at a time") if tags[:exclude].size > tag_query_limit
raise ::Post::SearchError.new("You cannot search for only excluded tags") unless has_constraints?
tag_query_sql << "!(" + escape_string_for_tsquery(tags[:exclude]).join(" | ") + ")"

View File

@@ -210,7 +210,7 @@ class Tag < ActiveRecord::Base
output[:include] << tag[1..-1]
elsif tag =~ /\*/
matches = Tag.name_matches(tag).all(:select => "name", :limit => CurrentUser.user.tag_query_limit, :order => "post_count DESC").map(&:name)
matches = Tag.name_matches(tag).all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name)
matches = ["~no_matches~"] if matches.empty?
output[:include] += matches

View File

@@ -416,9 +416,9 @@ class User < ActiveRecord::Base
def tag_query_limit
if is_privileged?
Danbooru.config.tag_query_limit
Danbooru.config.base_tag_query_limit
elsif is_platinum?
Danbooru.config.tag_query_limit * 2
Danbooru.config.base_tag_query_limit * 2
else
2
end

View File

@@ -36,7 +36,7 @@ module PostSetPresenters
end
def pattern_tags
Tag.name_matches(post_set.tag_string).all(:select => "name", :limit => CurrentUser.user.tag_query_limit, :order => "post_count DESC").map(&:name)
Tag.name_matches(post_set.tag_string).all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name)
end
def related_tags_for_group

View File

@@ -19,7 +19,7 @@
<tr>
<td><%= job.id %></td>
<% if CurrentUser.is_admin? %>
<td><%= job.handler[:method_name] %></td>
<td><%= raw print_handler(job) %></td>
<% end %>
<td><%= job.attempts %></td>
<td><%= job.priority %></td>

View File

@@ -118,10 +118,18 @@ module Danbooru
end
# Users cannot search for more than X regular tags at a time.
def tag_query_limit
def base_tag_query_limit
6
end
def tag_query_limit
if CurrentUser.user.present?
CurrentUser.user.tag_query_limit
else
base_tag_query_limit * 2
end
end
# Max number of posts to cache
def tag_subscription_post_limit
200