add new tag alias correction helper

This commit is contained in:
albert
2013-03-05 22:08:48 -05:00
parent e10f15d2db
commit d9a17d2378
11 changed files with 185 additions and 16 deletions

View File

@@ -34,12 +34,14 @@ class Tag < ActiveRecord::Base
end
module CountMethods
def counts_for(tag_names)
select_all_sql("SELECT name, post_count FROM tags WHERE name IN (?)", tag_names)
module ClassMethods
def counts_for(tag_names)
select_all_sql("SELECT name, post_count FROM tags WHERE name IN (?)", tag_names)
end
end
def fix_post_count
update_column(:post_count, Post.tag_match("#{name} status:any").count)
update_column(:post_count, Post.raw_tag_match(name).count)
end
end
@@ -462,7 +464,7 @@ class Tag < ActiveRecord::Base
end
include ApiMethods
extend CountMethods
include CountMethods
extend ViewCountMethods
include CategoryMethods
extend StatisticsMethods

View File

@@ -94,22 +94,17 @@ class TagAlias < ActiveRecord::Base
def clear_cache(host = Socket.gethostname)
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
Cache.delete("ta:#{Cache.sanitize(consequent_name)}")
end
def update_cache
Cache.put("ta:#{Cache.sanitize(antecedent_name)}", consequent_name)
Cache.delete("ta:#{Cache.sanitize(consequent_name)}")
end
def update_posts
Post.tag_match("#{antecedent_name} status:any").find_each do |post|
escaped_antecedent_name = Regexp.escape(antecedent_name)
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip
CurrentUser.scoped(creator, creator_ip_addr) do
post.update_attributes(
:tag_string => fixed_tags
)
end
Post.raw_tag_match(antecedent_name).each do |post|
post.save
end
end
end