Fix #4951: chartags:0 returning posts with chartags.
* Add fix script to fix posts with incorrect tag_count_* fields. * Simplify the code for updating tag_count_* fields (no functional change).
This commit is contained in:
@@ -29,7 +29,7 @@ class Post < ApplicationRecord
|
||||
validate :post_is_not_its_own_parent
|
||||
validate :uploader_is_not_limited, on: :create
|
||||
before_save :update_tag_post_counts
|
||||
before_save :set_tag_counts
|
||||
before_save :update_tag_category_counts
|
||||
before_create :autoban
|
||||
after_save :create_version
|
||||
after_save :update_parent_on_save
|
||||
@@ -323,22 +323,14 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def set_tag_count(category, tagcount)
|
||||
send("tag_count_#{category}=", tagcount)
|
||||
end
|
||||
|
||||
def inc_tag_count(category)
|
||||
set_tag_count(category, send("tag_count_#{category}") + 1)
|
||||
end
|
||||
|
||||
def set_tag_counts
|
||||
self.tag_count = 0
|
||||
TagCategory.categories.each {|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(TagCategory.reverse_mapping[category])
|
||||
# Update tag_count_general, tag_count_copyright, etc.
|
||||
def update_tag_category_counts
|
||||
TagCategory.categories.each do |category_name|
|
||||
tag_count = tags.select { |t| t.category_name.downcase == category_name }.size
|
||||
send("tag_count_#{category_name}=", tag_count)
|
||||
end
|
||||
|
||||
self.tag_count = tag_array.size
|
||||
end
|
||||
|
||||
def merge_old_changes
|
||||
|
||||
@@ -129,16 +129,9 @@ class Tag < ApplicationRecord
|
||||
Tag.where(name: tag_name).pick(:category).to_i
|
||||
end
|
||||
|
||||
def categories_for(tag_names, options = {})
|
||||
if options[:disable_caching]
|
||||
Array(tag_names).inject({}) do |hash, tag_name|
|
||||
hash[tag_name] = select_category_for(tag_name)
|
||||
hash
|
||||
end
|
||||
else
|
||||
Cache.get_multi(Array(tag_names), "tc") do |tag|
|
||||
Tag.select_category_for(tag)
|
||||
end
|
||||
def categories_for(tag_names)
|
||||
Cache.get_multi(Array(tag_names), "tc") do |tag|
|
||||
Tag.select_category_for(tag)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -157,7 +150,7 @@ class Tag < ApplicationRecord
|
||||
def update_category_post_counts
|
||||
Post.with_timeout(30_000) do
|
||||
Post.raw_tag_match(name).find_each do |post|
|
||||
post.set_tag_counts
|
||||
post.update_tag_category_counts
|
||||
post.save!
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user