Added fix script to update the correct tagcount for all posts
This commit is contained in:
@@ -624,10 +624,10 @@ class Post < ApplicationRecord
|
|||||||
set_tag_count(category,self.send("tag_count_#{category}") + 1)
|
set_tag_count(category,self.send("tag_count_#{category}") + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_tag_counts
|
def set_tag_counts(disable_cache = true)
|
||||||
self.tag_count = 0
|
self.tag_count = 0
|
||||||
TagCategory.categories.each {|x| set_tag_count(x,0)}
|
TagCategory.categories.each {|x| set_tag_count(x,0)}
|
||||||
categories = Tag.categories_for(tag_array, :disable_caching => true)
|
categories = Tag.categories_for(tag_array, :disable_caching => disable_cache)
|
||||||
categories.each_value do |category|
|
categories.each_value do |category|
|
||||||
self.tag_count += 1
|
self.tag_count += 1
|
||||||
inc_tag_count(TagCategory.reverse_mapping[category])
|
inc_tag_count(TagCategory.reverse_mapping[category])
|
||||||
@@ -1138,9 +1138,11 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
module CountMethods
|
module CountMethods
|
||||||
def fix_post_counts(post)
|
def fix_post_counts(post)
|
||||||
post.set_tag_counts
|
post.set_tag_counts(false)
|
||||||
args = Hash[TagCategory.categories.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
if post.changed?
|
||||||
post.update_columns(args)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_count_from_cache(tags)
|
def get_count_from_cache(tags)
|
||||||
|
|||||||
20
script/fixes/050_fix_post_tagcount.rb
Normal file
20
script/fixes/050_fix_post_tagcount.rb
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
|
||||||
|
|
||||||
|
CurrentUser.user = User.system
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
|
||||||
|
Post.without_timeout do
|
||||||
|
Post.where("updated_at > ? ", Date.parse("2017-11-12")).find_each do |post|
|
||||||
|
Post.fix_post_counts(post)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Tag.without_timeout do
|
||||||
|
Tag.where(category: Tag.categories.meta).find_each do |tag|
|
||||||
|
Post.raw_tag_match(tag.name).where("true").find_each do |post|
|
||||||
|
Post.fix_post_counts(post)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user