Moved non-config tag category info to its own class
This commit is contained in:
@@ -626,11 +626,11 @@ class Post < ApplicationRecord
|
||||
|
||||
def set_tag_counts
|
||||
self.tag_count = 0
|
||||
Danbooru.config.full_tag_config_info.each_key {|x| set_tag_count(x,0)}
|
||||
TagCategory.categories {|x| set_tag_count(x,0)}
|
||||
categories = Tag.categories_for(tag_array, :disable_caching => true)
|
||||
categories.each_value do |category|
|
||||
self.tag_count += 1
|
||||
inc_tag_count(Danbooru.config.reverse_tag_category_mapping[category])
|
||||
inc_tag_count(TagCategory.reverse_mapping[category])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -913,7 +913,7 @@ class Post < ApplicationRecord
|
||||
@typed_tags ||= {}
|
||||
@typed_tags[name] ||= begin
|
||||
tag_array.select do |tag|
|
||||
tag_categories[tag] == Danbooru.config.tag_category_mapping[name]
|
||||
tag_categories[tag] == TagCategory.mapping[name]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -926,20 +926,19 @@ class Post < ApplicationRecord
|
||||
@humanized_essential_tag_string ||= Cache.get("hets-#{id}", 1.hour.to_i) do
|
||||
string = []
|
||||
|
||||
Danbooru.config.humanized_tag_category_list.each do |category|
|
||||
humanizeddata = Danbooru.config.full_tag_config_info[category]["humanized"]
|
||||
typetags = typed_tags(category) - humanizeddata["exclusion"]
|
||||
if humanizeddata["slice"] > 0
|
||||
typetags = typetags.slice(0,humanizeddata["slice"]) + (typetags.length > humanizeddata["slice"] ? ["others"] : [])
|
||||
TagCategory.humanized_list.each do |category|
|
||||
typetags = typed_tags(category) - TagCategory.humanized_mapping[category]["exclusion"]
|
||||
if TagCategory.humanized_mapping[category]["slice"] > 0
|
||||
typetags = typetags.slice(0,TagCategory.humanized_mapping[category]["slice"]) + (typetags.length > TagCategory.humanized_mapping[category]["slice"] ? ["others"] : [])
|
||||
end
|
||||
if humanizeddata["regexmap"] != //
|
||||
if TagCategory.humanized_mapping[category]["regexmap"] != //
|
||||
typetags = typetags.map do |tag|
|
||||
tag.match(humanizeddata["regexmap"])[1]
|
||||
tag.match(TagCategory.humanized_mapping[category]["regexmap"])[1]
|
||||
end
|
||||
end
|
||||
if typetags.any?
|
||||
if category != "copyright" || typed_tags("character").any?
|
||||
string << humanizeddata["formatstr"] % typetags.to_sentence
|
||||
string << TagCategory.humanized_mapping[category]["formatstr"] % typetags.to_sentence
|
||||
else
|
||||
string << typetags.to_sentence
|
||||
end
|
||||
@@ -949,7 +948,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
Danbooru.config.full_tag_config_info.each_key do |category|
|
||||
TagCategory.categories.each do |category|
|
||||
define_method("tag_string_#{category}") do
|
||||
typed_tags(category).join(" ")
|
||||
end
|
||||
@@ -1140,7 +1139,7 @@ class Post < ApplicationRecord
|
||||
module CountMethods
|
||||
def fix_post_counts(post)
|
||||
post.set_tag_counts
|
||||
args = Hash[Danbooru.config.full_tag_config_info.keys.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||
args = Hash[TagCategory.categories.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||
post.update_columns(args)
|
||||
end
|
||||
|
||||
@@ -1523,7 +1522,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
list = super + [:uploader_name, :has_large, :has_visible_children, :children_ids] + Danbooru.config.full_tag_config_info.keys.map {|x| "tag_string_#{x}".to_sym}
|
||||
list = super + [:uploader_name, :has_large, :has_visible_children, :children_ids] + TagCategory.categories.map {|x| "tag_string_#{x}".to_sym}
|
||||
if visible?
|
||||
list += [:file_url, :large_file_url, :preview_file_url]
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Tag < ApplicationRecord
|
||||
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 1000
|
||||
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer|" +
|
||||
Danbooru.config.short_tag_name_mapping.keys.map {|x| "#{x}tags"}.join("|")
|
||||
TagCategory.short_name_list.map {|x| "#{x}tags"}.join("|")
|
||||
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
|
||||
attr_accessible :category, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
|
||||
attr_accessible :is_locked, :as => [:moderator, :admin]
|
||||
@@ -27,18 +27,18 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
class CategoryMapping
|
||||
Danbooru.config.reverse_tag_category_mapping.each do |value, category|
|
||||
TagCategory.reverse_mapping.each do |value, category|
|
||||
define_method(category) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def regexp
|
||||
@regexp ||= Regexp.compile(Danbooru.config.tag_category_mapping.keys.sort_by {|x| -x.size}.join("|"))
|
||||
@regexp ||= Regexp.compile(TagCategory.mapping.keys.sort_by {|x| -x.size}.join("|"))
|
||||
end
|
||||
|
||||
def value_for(string)
|
||||
Danbooru.config.tag_category_mapping[string.to_s.downcase] || 0
|
||||
TagCategory.mapping[string.to_s.downcase] || 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -125,7 +125,7 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
def category_name
|
||||
Danbooru.config.reverse_tag_category_mapping[category].capitalize
|
||||
TagCategory.reverse_mapping[category].capitalize
|
||||
end
|
||||
|
||||
def update_category_cache_for_all
|
||||
@@ -141,7 +141,7 @@ class Tag < ApplicationRecord
|
||||
Post.raw_tag_match(name).where("true /* Tag#update_category_post_counts */").find_each do |post|
|
||||
post.reload
|
||||
post.set_tag_counts
|
||||
args = Hash[Danbooru.config.full_tag_config_info.keys.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||
args = Hash[TagCategory.categories {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||
Post.where(:id => post.id).update_all(args)
|
||||
end
|
||||
end
|
||||
@@ -177,7 +177,7 @@ class Tag < ApplicationRecord
|
||||
counts = counts.to_a.select {|x| x[1] > trending_count_limit}
|
||||
counts = counts.map do |tag_name, recent_count|
|
||||
tag = Tag.find_or_create_by_name(tag_name)
|
||||
if tag.category == Danbooru.config.tag_category_mapping["artist"]
|
||||
if tag.category == Tag.categories.artist
|
||||
# we're not interested in artists in the trending list
|
||||
[tag_name, 0]
|
||||
else
|
||||
@@ -666,8 +666,8 @@ class Tag < ApplicationRecord
|
||||
when "tagcount"
|
||||
q[:post_tag_count] = parse_helper(g2)
|
||||
|
||||
when /(#{Danbooru.config.short_tag_name_mapping.keys.join("|")})tags/
|
||||
q["#{Danbooru.config.short_tag_name_mapping[$1]}_tag_count".to_sym] = parse_helper(g2)
|
||||
when /(#{TagCategory.short_name_regex})tags/
|
||||
q["#{TagCategory.short_name_mapping[$1]}_tag_count".to_sym] = parse_helper(g2)
|
||||
|
||||
when "parent"
|
||||
q[:parent] = g2.downcase
|
||||
|
||||
Reference in New Issue
Block a user